先将服务器的对应端口开放(开放端口为容器启动是指定的服务器本地端口)
修改 mysql root密码的步骤:
一、如果当前root用户authentication_string字段下有内容,可先将其设置为空,不然直接进行二步骤。
设置密码为空:
update user set authentication_string='' where user='root';
二、使用ALTER修改root用户密码,方法为 ALTER user 'root'@'localhost' IDENTIFIED BY '新密码'。如下:
alter user 'root'@'%' identified with mysql_native_password by 'xxxx';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'mypwd#2019';
或者 alter user 'root'@'localhost' identified with mysql_native_password by 'xxxx';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mypwd#2019'
提示:
root@后面是user表的Host字段的内容,新安装默认是localhost, 因为在这增加了远程访问,所以将localhost手动改成了%。
改完之后可执行:flush privileges;( 重新加载权限表 )
flush privileges;
注意:mysql8.0之后的版本,下面方法已经不适用。切记!!!
UPDATE user SET password=PASSWORD("新密码") WHERE user='用户名';