51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2047|回复: 1
打印 上一主题 下一主题

[原创] CentOS6.5系统MariaDB-10.1.*二进制包安装

[复制链接]
  • TA的每日心情
    无聊
    2017-11-26 18:46
  • 签到天数: 382 天

    连续签到: 1 天

    [LV.9]测试副司令

    跳转到指定楼层
    1#
    发表于 2017-3-24 11:08:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    环境:
    CentOS6.5 x86_64
    MariaDB-10.1.22       

    1、卸载自带MySQL
    # rpm -qa | grep -i mysql
    #会看到有几个安装项,使用rpm -e --nodeps逐一卸载即可
    rpm -e --nodeps perl-DBD-MySQL-4.013-3.el6.x86_64
    rpm -e --nodeps mysql-server-5.1.71-1.el6.x86_64
    rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
    rpm -e --nodeps mysql-5.1.71-1.el6.x86_64
    rpm -e --nodeps qt-mysql-4.6.2-26.el6_4.x86_64

    2、下载文件并上传到服务器中
    2.1、到官网下载mariadb-10.1.22-linux-x86_64.tar文件并上传
    2.2、切换到上传的文件下中并解压该文件
    # tar -xf mariadb-10.1.22-linux-x86_64.tar.gz
    2.3、移动该文件到并命名为MySQL到/usr/local
    # mv mariadb-10.1.22-linux-x86_64 /usr/local/mysql
    2.4、若MySQL用户群组已存在则不添加群组,否则添加用户MySQL用户
    # id mysql   ---若已存在,则使用该命令查看
    # useradd -g mysql mysql   ---若不存在,则使用该命令

    3、配置命令工具PATH和MAN PATH
    3.1、输出PATH到/etc/profile并立即启用
    # echo 'PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
    # source /etc/profile
    3.2、输出MAN PATH到/etc/man.config
    # echo MANPATH /usr/local/mysql/man/ >> /etc/man.config


    4、初始化MariaDB
    4.1、在mysql_install_db中初始化数据库
    # /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

    5、init脚本配置
    5.1、拷贝启动文件到/etc/init.d/mysql
    # cp -f /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
    5.2、输出相关信息到启动文件中
    # sed -i "/^basedir=/c basedir=/usr/local/mysql" /etc/init.d/mysql
    # sed -i "/^datadir=/c datadir=/usr/local/mysql/data" /etc/init.d/mysql

    6、主配置文件
    6.1、拷贝文件到主配置中
    # cp -f /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
    6.2、编辑文件并添加2行
    # vim /etc/my.cnf
    [mysqld]
    log-error       = /opt/mariadb/mysqld.log    #添加该项
    pid-file        = /opt/mariadb/mysqld.pid    #添加该项       
    6.3、拷贝logrotate配置文件,请按需微调
    # cp -f /usr/local/mysql/support-files/mysql-log-rotate /etc/logrotate.d/

    7、启动MySQL
    7.1、授权
    # chown -R mysql: /usr/local/mysql
    7.2、启动mysql并加入到开机自启中
    # service mysql start
    # chkconfig mysql on

    8、配置相关安全设置
    8.1、输出相关信息到安全设置中
    # sed -i "/^basedir=/c basedir=/usr/local/mysql" /usr/local/mysql/bin/mysql_secure_installation
    8.2、启动安全设置
    # /usr/local/mysql/bin/mysql_secure_installation
    print: /usr/local/mysql/bin/my_print_defaults

    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
          SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

    In order to log into MariaDB to secure it, we'll need the current
    password for the root user.  If you've just installed MariaDB, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.

    Enter current password for root (enter for none):
    OK, successfully used password, moving on...

    Setting the root password ensures that nobody can log into the MariaDB
    root user without the proper authorisation.

    Set root password? [Y/n] y
    New password:
    Re-enter new password:
    Password updated successfully!
    Reloading privilege tables..
    ... Success!


    By default, a MariaDB installation has an anonymous user, allowing anyone
    to log into MariaDB without having to have a user account created for
    them.  This is intended only for testing, and to make the installation
    go a bit smoother.  You should remove them before moving into a
    production environment.

    Remove anonymous users? [Y/n] y
    ... Success!

    Normally, root should only be allowed to connect from 'localhost'.  This
    ensures that someone cannot guess at the root password from the network.

    Disallow root login remotely? [Y/n] n
    ... skipping.

    By default, MariaDB comes with a database named 'test' that anyone can
    access.  This is also intended only for testing, and should be removed
    before moving into a production environment.

    Remove test database and access to it? [Y/n] n
    ... skipping.

    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.

    Reload privilege tables now? [Y/n] y
    ... Success!

    Cleaning up...

    All done!  If you've completed all of the above steps, your MariaDB
    installation should now be secure.

    Thanks for using MariaDB!
    提示:如没特殊要求,除设置root密码外,一路回车即可

    9、修改默认字符集
    9.1、修改my.cnf并添加内容
    # vim /etc/my.cnf
    [mysqld]
    init_connect = 'SET collation_connection = utf8_general_ci'
    init_connect = 'SET NAMES utf8'
    character_set_server = utf8
    collation_server = utf8_general_ci
    [mysqld_safe]
    init_connect = 'SET collation_connection = utf8_general_ci'
    init_connect = 'SET NAMES utf8'
    character_set_server = utf8
    collation_server = utf8_general_ci
    9.2、重启MySQL
    # service mysql restart
    9.3、进入数据库并查看编码字符
    # mysql -u root -p
    Enter password:

    MariaDB [(none)]> show variables like 'character_%';
    +--------------------------+----------------------------------+
    | Variable_name            | Value                            |
    +--------------------------+----------------------------------+
    | character_set_client     | utf8                             |
    | character_set_connection | utf8                             |
    | character_set_database   | utf8                             |
    | character_set_filesystem | binary                           |
    | character_set_results    | utf8                             |
    | character_set_server     | utf8                             |
    | character_set_system     | utf8                             |
    | character_sets_dir       | /usr/local/mysql/share/charsets/ |
    +--------------------------+----------------------------------+
    8 rows in set (0.00 sec)

    MariaDB [(none)]> show variables like 'collation%';
    +----------------------+-----------------+
    | Variable_name        | Value           |
    +----------------------+-----------------+
    | collation_connection | utf8_general_ci |
    | collation_database   | utf8_general_ci |
    | collation_server     | utf8_general_ci |
    +----------------------+-----------------+
    3 rows in set (0.00 sec)

    9.4、查看数据库,这里没有test数据库是在安全设置中已删除
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    3 rows in set (0.03 sec)

    MariaDB [(none)]> show engines;
    +--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
    | Engine             | Support | Comment                                                                                          | Transactions | XA   | Savepoints |
    +--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
    | MRG_MyISAM         | YES     | Collection of identical MyISAM tables                                                            | NO           | NO   | NO         |
    | CSV                | YES     | CSV storage engine                                                                               | NO           | NO   | NO         |
    | Aria               | YES     | Crash-safe tables with MyISAM heritage                                                           | NO           | NO   | NO         |
    | MyISAM             | YES     | MyISAM storage engine                                                                            | NO           | NO   | NO         |
    | MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables                                        | NO           | NO   | NO         |
    | InnoDB             | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, foreign keys and encryption for tables | YES          | YES  | YES        |
    | SEQUENCE           | YES     | Generated tables filled with sequential values                                                   | YES          | NO   | YES        |
    | PERFORMANCE_SCHEMA | YES     | Performance Schema                                                                               | NO           | NO   | NO         |
    +--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
    8 rows in set (0.00 sec)

    9.5、退出mysql
    MariaDB [(none)]> exit
    Bye











    评分

    参与人数 1测试积点 +10 收起 理由
    lsekfe + 10 赞一个!

    查看全部评分

    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-11-22 12:12 , Processed in 0.068929 second(s), 25 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表