一、安装方法
1、下载MySQL官方安装包
[root@localhost quincy]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch. rpm
2、执行yum -y install安装MySQL
[root@localhost quincy]# yum -y install mysql57-community-release-el7-10.noarch.rpm
二、启动MySQL服务
1、启功报错
Failed to issue method call: Unit mysql.service failed to load: No such file or directory.
2、查看错误日志发现有如下报错
[root@localhost log]# more /var/log/mysqld.log
3、执行以下命令初始化MySQL
[root@localhost log]# mysqld --initialize --user=mysql --console
结果报错
[ERROR] --initialize specified but the data directory has files in it.
需要删除MySQL下的所有文件
[root@localhost log]# cd /var/lib/mysql
[root@localhost mysql]# rm -rf *
再执行初始化命令
[root@localhost mysql]# mysqld --initialize --user=mysql --console (会给MySQL的root用户生成一个随机的密码,可以在mysql.log中找到)
启动MySQL
查询MySQL运行状态为active (running)
4、root用户登录MySQL
1)找到初始化MySQL时随机生成的密码
[root@localhost log]# cat /var/log/mysqld.log | grep localhost
2)登录MySQL修改root用户密码
初始密码为1)中获取的随机密码
修改密码
mysql> set password=password('quincy123')
---------------------------------------------------------------------------------------------------
mysql5.7.9以后版本更改为如下方式:
mysql> ALTER user 'root'@'localhost' IDENTIFIED BY 'quincy1201';
---------------------------------------------------------------------------------------------------