天天看点

ubuntu和deepin安装mysql-server后无法进入,update user set authentication_string=password(“密码“)语法报错

ubuntu19

  1. 固态硬盘到手后,安装ubuntu19,之后安装好mysql,但是在用命令登陆数据库的时候报错:
sudo apt install mysql-server#安装MySQL
mysql -u root -p#登录
access denied for user [email protected]#报错
           
  1. 于是我在mysqld.cnf文件末尾添加

    skip-grant-tables

    ,保存之后重启mysql 服务并登录,直接按enter键进入了数据库
sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf
#在文件末尾添加skip-grant-tables
service mysql restart #重启mysql服务
mysql -u root -p#登录
           

3.于是令authentication=’’,将

skip-grant-tables

注释重启mysql服务,然后也可以登陆数据库

update user set authentication_string='' where user='root';#root不设置密码
service mysql restart #在这之前记得要注释掉skip-grant-tables
           
  1. 如果我们想给root用户设置密码怎么办呢?
update user set plugin='mysql_native_password' where user='root'; #更改加密方式
alter user 'root'@'localhost' IDENTIFIED BY '123456';#设置密码
FLUSH PRIVILEGES;
           
  1. 然后就可以使用密码登陆了(mysql 的 root用户中有几个 password="", 为了安全起见用 delete 命令删除就行)

deepin15 (已经验证,没有错误)

  1. 在deepin 中安装MySQL(MariaDB):
sudo apt install mysql-server
           
  1. 登录mysql(MariaDB),在root权限下可以直接登录,当然也可以想上文Ubuntu中一样加入skip-grant-tabels
sudo mysql -u root -p
           
  1. 可以看到新版的MariaDB中使用unix-socket加密,我们将plugin修改为mysql_native_password
use mysql
update user set plugin='mysql_native_password' where user='root';
           
  1. 然后我们就可以设置密码了
update user set password=password('123456') where user='root'
update user set authentication_string=password('123456') where user='root'
如果上面报错的话,可以尝试执行:
alter user 'root'@'localhost' identified by '123456'
           
  1. 重启服务,登陆
exit
service mysql restart#重启服务
mysql -u root -p #登陆
           
  • 注意虽然作者竭力想写地准确无错,但仍会有所忽略,请多包含
  • 重点就是将root用户的加密方式plugin修改为mysql_native_password(真的吗?好像我在创建普通用户的时候不用诶?等我下一次重装数据库的时候再来验证吧,现在我真的不想验证,要吐了)
  • 这是作者第二次修正了(ubuntu部分),欢迎各位读者指正

本文参考:mysql8.XXX版本以后重置密码,修改加密方式解决Authentication plugin ‘XXX’ cannot be loaded问题

扩展阅读:mysql创建普通用户,并用其创建数据库