MySQL8忘记密码怎么办?

  1. sudo vim /etc/mysql/my.cnf

    增加如下内容,跳过密码检查。

    [mysqld]
    #(可选)
    #skip-name-resolve
    skip-grant-tables
    
  2. service mysql restart

  3. 进mysql(无需密码)

  4. flush privileges;

  5. update user set authentication_string=’’ where user='root’;

  6. alter user ‘root’@‘localhost’ identified with mysql_native_password by ‘newPassword’;(with mysql_native_password 可选)

    注意密码的复杂性。若想设置简单密码,修改下列属性

    • SHOW VARIABLES LIKE ‘validate_password%';
    • set global validate_password.policy=LOW;
    • set global validate_password.length=6;

    另外,注意查看host是‘localhost’还是‘%’

    • use mysql;
    • select user,host from user;
  7. sudo vim /etc/mysql/my.cnf

    复原my.cnf

  8. service mysql restart

  9. mysql -u root -p(验证)


MySQL8配置远程连接

  1. 进mysql(root localhost)

  2. use mysql;

  3. select host, user, authentication_string, plugin from user;

  4. create user ‘root’@'%’ identified by ‘你自己的mysql密码’;

  5. grant all privileges on . to ‘root’@'%';

  6. flush privileges;

  7. sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

    注释掉:ind-address = 127.0.0.1

  8. service mysql restart

https://blog.csdn.net/winterking3/article/details/86080434

https://blog.csdn.net/hello_world_qwp/article/details/79551789

https://blog.csdn.net/q258523454/article/details/84555847

https://www.jb51.net/article/179011.htm

MySQL的安装可以看这篇

https://forum.ubuntu.org.cn/viewtopic.php?t=491034