CentOS Linux release 7.3.1611下安装Generic Binaries MySQL

  1. 首先创建对应的mysql用户和组:
    shell >groupadd mysql
    shell >useradd -r -g mysql -s /bin/false mysql
  2. 然后解压下载mysql安装包:
    shell >tar -zxf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
  3. 解压后得到一个文件夹:mysql-5.7.18-linux-glibc2.5-x86_64,然后重命名改文件夹:
    shell >mv mysql-5.7.18-linux-glibc2.5-x86_64 mysql
  4. 将重命名后的mysql文件夹复制到/usr/local目录下:
    shell >cp -fr mysql /usr/local
  5. 进入/usr/local/mysql目录中,并创建mysql-files目录:
    shell >cd /usr/local/mysql
    shell >mkdir mysql-files
  6. 更改mysql-files目录的读写权限,“750”表示“rwx r-x ---”,即所属用户具有完全的权限,同组用户具有读和执行的权限,没有写权限,其它用户没有任何操作该目录的权限。4代码r,2代表w,1代表x,所以7=4+2+1,5=4+1。
    shell >chmod 750 mysql-files
  7. 变更mysql目录的所属用户和所属组为mysql:
    shell >chown -R mysql . //-R表示递归的执行 .表示当前路径,也就是mysql目录
    shell >chgrp -R mysql .
  8. 5.7.6以前的版本需要执行shell >bin/mysql_install_db --user=mysql来初始化数据库,5.7.6以及之后的版本用shell >bin/mysqld --initialize --user=mysql初始化数据库。我安装的是5.7.18的版本,所以执行后者:
    shell >bin/mysqld --initialize --user=mysql
    执行后控制台输出一下内容:
    2017-05-26T05:00:03.904689Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2017-05-26T05:00:04.472001Z 0 [Warning] InnoDB: New log files created, LSN=45790 2017-05-26T05:00:06.146190Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2017-05-26T05:00:06.209077Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2f62b4a2-41d0-11e7-8cb8-525400a2d362. 2017-05-26T05:00:06.210654Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2017-05-26T05:00:06.211681Z 1 [Note] A temporary password is generated for root@localhost: heU45>Y/mcy1
    最后一行可以看到它会自动初始化一个root密码。
  9. 生成ssl密钥:
    shell >bin/mysql_ssl_rsa_setup
  10. 变更目录所属组和所属用户:
    shell >chown -R root .
    shell >chown -R mysql mysql-files
  11. 此时可以尝试启动mysql服务:
    shell >bin/mysqld_safe --user=mysql &
    报错:
    [root@localhost mysql]# 2017-05-26T05:10:39.464104Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
    打开mysql的默认配置文件,位于/etc目录下:
    shell >vim /etc/my.cnf
    可以看到以下内容:
    [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid !includedir /etc/my.cnf.d
    log-error指定的目录确实不存在,我们创建一下并且改为mysql,将配置文件中所有mariadb改为mysql。
    [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 [mysqld_safe] log-error=/var/log/mysql/mysql.log pid-file=/var/run/mysql/mysql.pid !includedir /etc/my.cnf.d
    然后创建目录。
    shell >cd /var/log && mkdir mysql
    shell >touch /var/log/mysql/mysql.log
    更改改mysql的所属用户和所属组为mysql
    shell >chown -R mysql /var/log/mysql
    shell >chgrp -R mysql /var/log/mysql
    再次尝试启动失败,查看刚才创建的日志文件,发现如下错误信息:
    2017-05-26T05:21:35.467519Z 0 [ERROR] /usr/local/mysql/bin/mysqld: Can't create/write to file '/var/run/mysql/mysql.pid' (Errcode: 2 - No such file or directory) 2017-05-26T05:21:35.467536Z 0 [ERROR] Can't start server: can't create PID file: No such file or directory
    查看/var/run目录,发现没有mysql目录,创建一个。
    shell >mkdir mysql
    shell >chown -R mysql mysql
    shell >chgrp -R mysql mysql
    再次启动成功,但是查看日志时发现一个ERROR:
    2017-05-26T05:29:01.061530Z 0 [ERROR] SSL error: Unable to get private key from 'server-key.pem'
    查找该文件,发现位于/var/lib/mysql中。原来它只有root用户可以读取。将其所属组和所属用户都改为mysql:
    shell >chown mysql server-key.pem
    shell >chgrp mysql server-key.pem
    再次启动,问题解决。
  12. 查看进程,我们可以看到mysql的启动参数:
    shell >ps -ef | grep mysql
    /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysql/mysql.log --pid-file=/var/run/mysql/mysql.pid --socket=/var/lib/mysql/mysql.sock

你可能感兴趣的:(CentOS Linux release 7.3.1611下安装Generic Binaries MySQL)