mysql5.7 server 安装时root用户密码找不到

2019-05-14  本文已影响0人  finlu

使用以下方式可以无密码进入mysql:

  1. 以系统管理员权限进入mysql
    sudo mysql -uroot
    
  2. 以debian用户的账号密码进入mysql
    • 进入 /etc/mysql/debian.cnf 中找到账号(user)和密码(password)
    • 然后登陆到 mysql
      mysql -u<user> -p<password>
      
  3. 编辑 /etc/mysql/mysql.conf.d/mysqld.cnf 文件。
    • [mysqld]下方的skip-external-locking下面添加一行:
      skip-grant-tables
      
    • 重启 mysql 服务
      sudo service mysql restart
      

成功进入mysql后,在mysql的命令行中通过输入以下命令来将 root 用户的密码设置为 root

use mysql;
update mysql.user set authentication_string=password('root') where user='root' and Host ='localhost';
update user set plugin="mysql_native_password"; 
flush privileges;

最后重其服务就可以用我们刚刚设置的密码进行登陆了。(设置了 skip-grant-tables 参数的同学别忘记把这个参数删掉或在注释掉!!)

上一篇 下一篇

猜你喜欢

热点阅读