成功方案
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[[email protected] ~]# mysql -u root mysql
mysql> update user set authentication_string=PASSWORD(‘passw0rd‘) where user=‘root‘;
[[email protected] ~]# mysql -u root -p
Enter password:
登陆之后还需之行下面的语句修改密码,使其符合规则
alter user ‘root‘@‘localhost‘ IDENTIFIED BY ‘[email protected]‘ PASSWORD EXPIRE;
或者这一句
SET PASSWORD = PASSWORD(‘[email protected]‘);
使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
时间: 2024-10-12 14:01:10