(Debian系统)
1. service mysql stop
2. mysqld_safe --skip-grant-tables
3. 另开控制台,继续下面步骤
4. mysql -u root,使用空密码登陆
5. show databases;
6. use mysql;
7. update user set Password=password('Ts123456') where user='root';
8. flush privileges;
9. quit;
a. mysql -u root -p
b. 123456
(CentOS系统)
service mysql stop
mysqld_safe --skip-grant-tables&
mysql -u root -p
使用空密码登陆
use mysql;
update user set authentication_string=Password('Ts123456') where user='root';
flush privileges;
SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
flush privileges;
如此还可以解决如下问题:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql本地登陆
mysql -u root -p
123456
mysql远程登陆
mysql -h 192.168.2.100 -u root -p
123456
mysql开启远程访问
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;