`
izuoyan
  • 浏览: 8914567 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

今天遇到两个问题:Can't connect to MySQL server 与 Access denied for user !

阅读更多

问题一:本机(localhost)连接一切正常,但是无法从其他电脑上登入 MySQL 数据库!


下面是 /etc/mysql/my.cnf 中的一段摘录:


# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 10.0.0.1 # 127.0.0.1

其中说明 MySQL默认设定为只在 localhost 进行侦听,所以如果登录的 MySQL Client 与 MySQL Server 不为同一台电脑的话,MySQL 是不会响应的。故需要把这里的 bind-address 修改为此台电脑的 external IP 即可。

问题二:ERROR 1045 (28000): Access denied for user 'root'@'10.0.0.1' (using password: YES) !

这个也是颇有意思,首先看看原本系统表中的资料:


mysql> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> SELECT Host FROM user WHERE user='root';
+-----------+
| Host |
+-----------+
| sharkwang |
| localhost |
+-----------+
2 rows in set (0.00 sec)

恩,这里除了有 localhost 外,居然还有一个 sharkwang ,而我连接的时候是用IP而不是hostname !

所以,有2个方案:

1. 在 MySQL Client 所在的电脑上面,修改 /etc/hosts 文件,加入 hostname 和 IP 的映射关系。

登录方式为: shell> mysql -h <mysql_server_hostname> -u root -p

2. 在 MySQL 数据库的 user 表中增加一条记录,内容参照:

SELECT * FROM user WHERE User='root' AND Host='localhost'

然后把 Host 对应的值修改为 MySQL Server 的 external IP。

登录方式为: shell> mysql -h <mysql_server_ip> -u root -p


分享到:
评论

相关推荐

    解决mysql登录错误:’Access denied for user ‘root’@’localhost’

    首先是不知道怎么忽然mysql用命令行,workbench都登录不了,都提示’Access denied for user ‘root’@’localhost’。 数据库卸载重装了几次都不行。好像感觉数据清理不干净。解决的过程遇到的坑,这里记录分享下。...

    php 不能连接数据库 php error Can’t connect to local MySQL server

    ?php $link=mysql_connect(‘localhost’,’root’,... 运行后报错 Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ 但在 命令行中能进入mysql [root@localhost local]# mysql -u root -p E

    mysql忘记密码怎么办

    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 如果说出现这个一般就是因为MySQL没有起来 [root@localhost ~]# mysql -uroot -p ERROR 1045 (28000):...

    mysql安装失败

    Access denied for user 'root'@'localhost' (using password: YES) If a personal firewall is running on your machine, please make sure you have opened the TCP port 3306 for connections. Otherwise no ...

    PHP错误Warning:mysql_query()解决方法

    php提示错误:Warning: mysql_query() [function.mysql-query]: Access denied for user ‘ODBC’@’localhost’ (using password: NO) 代码: &lt;?php class mysqlClass { function mysqlClass($host='localhost...

    linux mysql忘记密码的多种解决或Access denied for user ‘root’@’localhost’

    我的系统是ubuntu6.06,最近新装好的mysql在进入mysql工具时,总是有错误提示: # mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO) 使用...

    MySQL忘记root密码错误号码1045的解决办法

    主要介绍了MySQL忘记root密码错误号码1045的解决办法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

    MySQL中文参考手册

    o 6.13 存取拒绝(Access Denied)错误的原因 o 6.14 怎样使MySQL安全以对抗解密高手(cracker) * 7 MySQL 语言参考 o 7.1 文字:怎样写字符串和数字 + 7.1.1 字符串 + 7.1.2 数字 + 7.1.3 十六进制值 + 7.1.4 ...

    MYSQL

    Apache一起使用 MySQL 18 问题和常见的错误 18.1 如果 MySQL总是崩溃怎么办 18.2 使用 MySQL 时一些常见错误 18.2.1 MySQL server has gone away错误 18.2.2 Can't connect to [local] MySQL ...

    单例模式实现mysql的PHP类.zip

    defined('ACC')||exit('Access Denied'); // 封装mysql操作类,包括连接功能,及查询功能. class mysql extends absdb{  protected static $ins = null;  protected $host; // 主机名  protected...

    解决重置Mysql root用户账号密码问题

    mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: YES)' 解决方法 如下,重置mysql root用户密码 # service mysqld stop # 进入mysql...

    mysql工具类

    里面有详解(1045 access denied for user 'root'@'.txt;2003 cant connect to mysql server on(未安装软件到系统造成的问题).doc;mysql-5.6.24-win32.msi)

    MySQL中文参考手册.chm

    6.13 存取拒绝(Access Denied)错误的原因 6.14 怎样使MySQL安全以对抗解密高手(cracker) 7 MySQL 语言参考 7.1 文字:怎样写字符串和数字 7.1.1 字符串 7.1.2 数字 7.1.3 十六进制...

Global site tag (gtag.js) - Google Analytics