修改mysql 8.0.16 root 密码--mac

https://blog.csdn.net/HECTOR_1368391900/article/details/90732097

https://my.oschina.net/u/3251146/blog/2885657

序言:

      如果是首次安装mysql数据,可以查看日志文件,能找到随机的密码,日志文件在配置文件(/etc/my.cnf)

      less  /var/log/mysqld.log

    如果忘记root密码,重复下面的步骤 能够重置root密码

1. 修改Mysql配置文件

       vim /etc/my.cnf

     添加如下内容:

      default-authentication-plugin=mysql_native_password
      symbolic-links=0
      skip-grant-tables

2.重启mysql服务

    systemctl restart mysqld

3.无密码登录

   mysql -u root -p 
   按 enter键 进入

4.修改密码

    use mysql;
    select user,host,authentication_string from user;
    ### 密码设置为空
    update user set authentication_string='' where user='root';

     flush privileges;
     quit;

5.退出,重新登录 进行修改密码

    去掉 步骤1 配置的内容 跳过密码登录进去的
    #default-authentication-plugin=mysql_native_password
    #symbolic-links=0
    #skip-grant-tables
    
    重复步骤2 步骤3

6.修改root密码

    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'RootPwd@123456';

    ### 密码必须包含两个大写字母 、特殊符号、 字母、 数字

7.开放远程登录

   update user set host ='%' where user='root';

   ### 同时也要检查 云服务器的安全组是否开启 mysql(3306) 端口号

   ### 也要检查 防火墙 开启对外  mysql(3306) 端口号

posted @ 2019-08-08 14:34  zzfx  阅读(1492)  评论(1编辑  收藏  举报