1.环境
centos7、pxc5.7
2.问题描述
在部署PXC环境时,第三台服务器(也就是第二个从机)启动Mysql后,查询初始密码登陆ROOT用户一直说密码错误,这样就无法修改ROOT口令,设置其他用户。于是需要想办法解决。
3.方法
/etc/percona-xtradb-cluster.conf.d/mysqld.cnf
[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程
然后关闭mysql服务,重新启动
systemctl stop mysql
systemctl start mysql
随后在命令行输入 mysql -uroot -p
提示输入密码,直接按回车进入mysql命令行,输入
update user set password=password('XXXXXX') where user='root';
提示错误:ERROR 1046 (3D000): No database selected
需要先选中mysql,输入
use mysql
然后再
update user set password=password('XXXXXX') where user='root';
报新错误:ERROR 1054 (42S22): Unknown column 'password' in 'field list'
然后修改SQL语句用如下:
alter user 'root'@'localhost' identified by 'XXXXXXX';
还报错:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
于是在命令行再输入:
flush privileges;
root密码已经修改成功
然后关闭重启MYSQL
systemctl stop mysql
systemctl start mysql
随后在命令行输入 mysql -uroot -p
输入新设置密码,成功登陆