mysql相关问题解决

 

一.ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:yes)

问题分析:一般是密码错误,修改密码步骤如下。

1.在my.cnf最后添加

skip-grant-tables

2.重启mysql服务

#service mysqld restart

3.设置root密码

mysql8.0--->alter user ‘root’@’localhost’ IDENTIFIED BY ‘你的密码’; 

mysql5.7--->update user set password=password('123456') where user = 'root';

4.可能报下面错误

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

5.刷新权限后执行修改密码操作

mysql>flush privileges;

6.删除my.cnf中添加的内容并重启mysql

二.navicat for mysql 链接时报错:1251-Client does not support authentication protocol requested by server

问题分析:navicat版本不支持mysql8.0的认证插件。

1.进入mysql数据库,执行下面命令,查看plugin插件

mysql>use mysql;
mysql>select user,host,plugin from user;

  

2.这里面的caching_sha2_password 是mysql8.0默认的认证插件, 必须使用支持此插件的navicat 客户端版本。

这里可以将caching_sha2_password 降级为mysql_native_password即可。

mysql>alter user 'root'@'%' identified with mysql_native_password by '你的密码'; 
mysql>flush privileges;

      

三.Mysql---Operation ALTER USER failed for 'root'@'localhost'

问题分析:root对应的host不正确,不是localhost,而是%。

1.进入mysql数据库,查看user,host

mysql> use mysql;
mysql>select user,host from user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| mysqld           | %         |
| root             | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
+------------------+-----------+

2.注意到root用户对用的host是%,要修改密码,要使用下面的指令

mysql>alter user 'root' @'%' identified by '你的密码';
mysql>flush privileges;  

 3.也可以修改root对应的host为localhost在进行alter操作

mysql>update user set host='localhost' where user='root';

 

四.mysql2003 can't connect to Mysql server on ...(10038)


问题分析:可能有以下三种

  1.用户的host是localhost,只允许本地登录。

  2.权限不支持,开启权限 。

  3.端口3306未打开。

1.修改用户的host为%

mysql> use mysql;
mysql> update user set host='%' where user='root';
mysql> flush privileges;

2.开启权限

mysql> grant all privileges on *.* to 'root'@'%' identified by '数据库密码' with grant option;
mysql> flush privileges;

3.开启3306端口(centos系统)

3.1 查看是否开启3306端口

#netstat -tunlp

3.2 启动防火墙

#systemctl start firewalld

3.3 添加3306端口

#firewall-cmd --permanent --add-port=3306/tcp 
#firewall-cmd --reload
原文地址:https://www.cnblogs.com/peter_zhang/p/mysql_problem.html