成功方案
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[root@localhost ~]# mysql -u root mysql
mysql> update user set authentication_string=PASSWORD('passw0rd') where user='root';
[root@localhost ~]# mysql -u root -p
Enter password:
登陸之後還需之行下面的語句修改密碼,使其符合規則
alter user 'root'@'localhost' IDENTIFIED BY 'Passw0rd@' PASSWORD EXPIRE;
或者這一句
SET PASSWORD = PASSWORD('Passw0rd@');
使mysql的root用戶可以遠程鏈接:
mysql -u root –p
mysql>use mysql;
mysql>
update
user
set
host =
'%'
where
user
=
'root'
;
mysql>
select
host,
user
from
user
;
FLUSH
PRIVILEGES
失敗方案
創建mysql-init文件,內容如下:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
然後執行 sudo mysqld_safe --init-file=mysql-init &
然後刪除mysql-init