(1)关闭服务
systemctl stop mysql
(2)查看配置文件位置
首先先看看你的mysql在哪,通过which命令
which mysql
显示出目录比如我的是下面这个
/usr/bin/mysql
接下来就可以针对这个目录通过一些命令查看配置文件在哪了,如下
/usr/bin/mysql --verbose --help | grep -A 1 ‘Default options’
然后在下面会出现一些信息比如我的
Default options are read from the following files in the given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
这个信息的意思是:
服务器首先读取的是/etc/mysql/my.cnf文件,如果前一个文件不存在则继续读/etc/my.cnf文件,如若还不存在便会去读~/.my.cnf文件
(3)修改配置文件 加上这两行
[mysqld]
skip-grant-tables
(4)重启MySQL服务
systemctl start mysql
(5)登录进去,更改配置
mysql -u root
use mysql
mysql> update mysql.user set authentication_string=‘root’ where user=‘root’;//有的教程更改密码输入update mysql.user set authentication_string=password(‘root’) where user=‘root’;可能是版本问题
mysql> flush privileges; //刷新配置