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 root@localhost#报错
  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创建普通用户,并用其创建数据库

  • 4
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值