【Ubuntu】修改MySQL密码5.7以及以上

1、sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

     添加 skip-grant-tables

2、启动mysql,使用命令sudo /etc/init.d/mysql start

3、登陆 mysql -uroot

4、执行语句

     (1) update mysql.user set authentication_string=password('newpasswd') where user='root';

          flush privileges;

    (2) update mysql.user set host='%' where user='root';

          flush privileges;

    (3) update mysql.user set plugin="mysql_native_password" where User='root';

          flush privileges;

    (4) grant all privileges on *.* to 'root'@'%' identified by 'newpasswd with grant option;

          flush privileges;

5、vim /etc/mysql/mysql.conf.d/mysqld.cnf

     去掉  skip-grant-tables

              bing-address=127.0.0.1(其他机器可以访问)

   【Ubuntu】修改MySQL密码5.7以及以上

6、sudo /etc/init.d/mysql restart 重启服务

7、用其他机器连接数据库试试!(记得关闭防火墙)