mysql 远程连接可以,本地连接报错,mysql本地连接
使用python的MySQLdb库连接本地的mysql数据库,报错如下:
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'***-vuldb.local' (using password: YES)")
解决方法:
添加'root'@'***-vuldb.local'的访问权限
授权root用户拥有testDB数据库的所有权限(某个数据库的所有权限):
mysql>grant all privileges on testDB.* to root@***-vuldb.localhost identified by '1234';
mysql>flush privileges;//刷新系统权限表
格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码";
参考:http://www.cnblogs.com/fly1988happy/archive/2011/12/15/2288554.html
远程能连接的话,本地一定是能连接的,你现在说“不能连接”了,我估计可能是密码错误,你看看结果,同一个用户远程和本地的密码是不同的。
如果我猜中了,你用远程连接设置一下本地用户的密码,或者删除本地用户密码,既可解决问题。
确认你的mysql服务已经打开;
确认你的mysql的端口配置正确;
确认你的远程权限配置正确;
如果还是连不上,看看是什么连接错误,贴个图!