mysql 连接问题

1.linux连接报错(Xshell连接报错)

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

# /etc/init.d/mysql stop 
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 
# mysql -u root mysql 
mysql> UPDATE user SET Password=PASSWORD(’root’) where USER=’root’; 
mysql> FLUSH PRIVILEGES; 
mysql> quit 
# /etc/init.d/mysql restart 
# mysql -uroot -p 
Enter password: <输入新设的密码newpassword> 
mysql>

2.本地连接报错(navicat连接报错)

1.检查防火墙是否关闭

2.1。 改表法(会报错就用第二个)。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"

Sql代码 复制代码

   1. mysql -u root -p
   2. use mysql;  
   3. mysql>update user set host = '%' where user = 'root';  
   4. mysql>select host, user from user;

2.2. 授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。

Sql代码 复制代码
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

FLUSH PRIVILEGES;

原文地址:https://www.cnblogs.com/ymk0375/p/6554932.html