一.更改root密码
1.mysqladmin直接修改
mysqladmin -uroot -p"SH123.com" password "ty123.com"
2.登陆MySQL修改相应表
mysql> desc mysql.user;
mysql> select host,user,authentication_string from mysql.user;
mysql> update mysql.user set authentication_string=password("SH123.com") where user="root" and host=‘localhost‘;
//刷新授权表
mysql> flush privileges;
二.忘记密码:
vi /etc/my.cnf
[mysqld]
basedir=/soft/mysql
datadir=/soft/mysql/data
skip-grant-tables # 新增授权表
//重启MySQL数据库
systemctl restart mysqld.service
//登陆MySQL修改相应表
mysql> update mysql.user set authentication_string=password("ty123.com") where user=‘root‘ and host=‘localhost‘;
mysql> desc mysql.user;
mysql> select host,user,authentication_string from mysql.user;
mysql> update mysql.user set authentication_string=password("SH123.com") where user="root" and host=‘localhost‘;
//刷新授权表
mysql> flush privileges;
注:登陆成功后
注释skip-grant-tables 使用新的密码登陆