版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
ubuntu19
- 固态硬盘到手后,安装ubuntu19,之后安装好mysql,但是在用命令登陆数据库的时候报错:
sudo apt install mysql-server#安装MySQL
mysql -u root -p#登录
access denied for user root@localhost#报错
- 于是我在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#登录
- 现在修改root密码,但是显示rootadmin那里有语法错误,推断是password()的问题,是因为MySql8之后加密方式采用caching_sha2_password
update user set authentication_string=password('rootadmin') where user='root';#尝试着用修改密码,结果显示在rootadmin附近有错误,是因为MySql8之后加密方式采用caching_sha2_password
- 于是令authentication=’’,将
skip-grant-tables
注释重启mysql服务,然后也可以登陆数据库
update user set authentication_string='' where user='root';#root不设置密码
service mysql restart #在这之前记得要只是掉skip-grant-tables
- 如果我们想给root用户设置密码怎么办呢?
alter user 'root'@'localhost' INDENTIFIED BY '123456';#密码设置为
- 那么可不可以使用update的方式修改密码呢? 当然可以,不过在这之前要把加密方式 修改为mysql_native_password
update user set plugin='mysql_native_password' where user='root'; #修改加密方式
update user set authentication_string=password('123456'); #设置密码
FLUSH PRIVILEGES;
- 然后就可以使用密码登陆了
deepin15
- 在deepin 中安装MySQL(MariaDB):
sudo apt install mysql-server
- 登录mysql(MariaDB),在root权限下可以直接登录,当然也可以想上文Ubuntu中一样加入skip-grant-tabels
sudo mysql -u root -p
- 可以看到新版的MariaDB中使用unix-socket加密,我们将plugin修改为mysql_native_password
update user set plugin='mysql_native_password' where user='root'
- 然后我们就可以设置密码了
update user set password=password('123456') where user='root'
update user set authentication=password('123456') where user='root'
- 重启服务,登陆
service mysql restart#重启服务
mysql -u root -p #登陆
- 注意虽然作者竭力想写地准确无错,但仍会有所忽略,请多包含
- 重点就是将root用户的加密方式plugin修改为mysql_native_password
本文参考:mysql8.XXX版本以后重置密码,修改加密方式解决Authentication plugin ‘XXX’ cannot be loaded问题