【linux mysql】mysql高版本8.0.23版本密码修改总结

时间:2025-01-25 07:32:31

mysql 8.0 版本,由于增加了一些安全策略等限制,所以修改用户密码会稍微麻烦些。下面是针对这个高版本的总结。

一、配置/etc/ 文件 免密码登录mysql

vim /etc/
# 增加这两行命令
skip-grant-tables
default-authentication-plugin=mysql_native_password

重启启动mysql

service mysqld restart

之后不需要输入密码,直接进入mysql 重置密码,输入密码时按空格键

[root@data01 ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 30
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

二、进入mysql 数据库

use mysql;
update user set authentication_string='' where user='root';
FLUSH PRIVILEGES;
ALTER user 'root' IDENTIFIED BY 'MyNewPass4!';
FLUSH PRIVILEGES;

三、若你设置的密码过于简单,系统会提示密码简单,那么怎么解决呢,重新设置密码安全规则策略
提示密码太简单

set global validate_password.length =4 ;
set global validate_password.policy =0;
ALTER user 'root' IDENTIFIED BY 'MyNewPass4!';
FLUSH PRIVILEGES;

四、navicat连接MySQL8.0出现2059错误

在navicat链接mysql8以后的版本时,会出现2059的错误,这个错误出现的原因是在mysql8之前的版本中加密规则为mysql_native_password,而在mysql8以后的加密规则为caching_sha2_password。解决此问题有两种方法,一种是更新navicat驱动来解决此问题,一种是将mysql用户登录的加密规则修改为mysql_native_password。本文采用第二种方式。

方法二:

[mysqld]
default_authentication_plugin=mysql_native_password

五、ERROR 1449 (HY000): The user specified as a definer (‘’@‘localhost’) does not exist

解决方案:

/weixin_44412864/article/details/112849381

mysql> use mysql
Database changed
mysql> select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
+-----------+------------------+
4 rows in set (0.00 sec)

mysql> create user '  '@'% 'identified by' password ';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> create user '  '@'% 'identified by 'MyNewPass4!';
Query OK, 0 rows affected (0.01 sec)

mysql>  grant all privileges on *.* to ''@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> 

六、设置密码以及开放外网

#进入mysql 控台
mysql  mysql -uroot -p
#修改密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'MyNewPass4!';
#刷新权限
flush privileges;  

开放外网
 #选择mysql数据库
 use mysql;
 #修改root 用户的连接地址现在  localhost 为本机 也可指定固定ip 此处 % 开启所有ip访问
 update user set host='%' where user='root';
 #刷新权限
 flush privileges;

七、之后再回到/etc/ 文件 修改配置

vim /etc/my.cnf
将这行免密登录注释掉
#skip-grant-tables

再重启mysql 服务即可。

service mysqld restart

大功告成~