MySQL 下载地址:
并按如下方式选择来下载安装包。
1. 设置配置文件/etc/my.cnmore /etc/my.cnf
[client]
port = 3306 socket = /tmp/mysql.sockdefault-character-set=utf8[mysqld] user=mysql port = 3306 server_id = 1 socket=/tmp/mysql.sock basedir =/usr/local/mysql datadir =/usr/local/mysql/data pid-file=/usr/local/mysql/data/mysqld.pid log-error=/usr/local/mysql/log/mysql-error.logcharacter_set_server=utf8max_connections=1000
2.新建用户和用户组
groupadd mysqluseradd -g mysql mysql
3.解压mysql二进制文件到目录/usr/local目录下,并重命名为mysql
cd /usr/local
tar -xf /root/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gzmv mysql-5.7.18-linux-glibc2.5-x86_64 mysqlchown -R mysql:mysql mysqlcd /usr/local/mysqlmkdir logchown -R mysql:mysql logchmod 755 logcd /usr/local/mysql/logtouch mysql-error.logchmod 755 mysql-error.logchown mysql:mysql mysql-error.logmkdir -p /usr/local/mysql/socketfile
chown -R mysql:mysql /usr/local/mysql/socketfile
4.初始化数据库
cd /usr/local/mysqlbin/mysqld --initialize --user=mysql
初始化数据库后的密码存放在mysql-error.log文件中
[mysql@SaltStack-Minion log]$ more mysql-error.log 2017-09-25T01:02:36.182707Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2017-09-25T01:02:42.076463Z 0 [Warning] InnoDB: New log files created, LSN=457902017-09-25T01:02:42.464764Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2017-09-25T01:02:42.916407Z 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: 3c1e3858-a18d-11e7-b261-000c299cd645.2017-09-25T01:02:43.104917Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2017-09-25T01:02:43.124083Z 1 [Note] A temporary password is generated for root@localhost: O4Cfoig_gXui2017-09-25T01:02:53.184964Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
5.设置环境变量(root用户和mysql用户都添加)
在~/.bash_profile文件中添加mysql的安装目录,添加后的结果如下:
[root@CentOS6 mysql]# vi ~/.bash_profile# .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then . ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/bin:/usr/local/mysql/binexport PATH
#使修改生效
source ~/.bash_profile
6.设置service服务自启动
cd /usr/local/mysqlcp support-files/mysql.server /etc/init.d/mysql.serverservice mysql.server startservice mysql.server restartservice mysql.server stop
7.修改MySQL的root密码
set password for root@localhost = password('mysql'); flush privileges;
8.当启动MySQL数据库报错时,尝试采用如下方式解决:
报错信息:
Starting MySQL.. ERROR! The server quit without updating PID file
解决方法:
(1)首先检查mysql日志文件中报错信息(一般mysql日志文件会写在/etc/my.cnf这个文件中);
(2)找到报错信息之后,然后逐步确诊原因即可;
(3)上述问题,我是通过删除mysql.sock文件(在/etc/my.cnf文件中会记录该文件的所在目录),然后再次数据库,问题解决;