lamp mysql连接不上_Ubuntu Server中LAMP下MySQL无法远程连接问题1130

Ubuntu Server中LAMP下MySQL无法远程连接该怎么办:

很常见的问题发生了,我们怎么处理它?

环境:ubuntu Server (版本8.04以上对于LAMP应用都大同小异), cl@ubuntu.

目的:安装LAMP重新配置RT系统。

软件:服务器端已安装LAMP组件,MySQL5.1版本;客户端使用Navicat进行远程连接。

问题② 提示”is not allowed to connect to this MySQL server” ,如图2

4b33fbc1fb2a06bb2e0ed69e0d20b362.gif

对于数据库的远程连接不外乎两方面入手:1、客户端至服务器端的连通性。2、服务器端没有合理配置。当然非要加上客户端也没有配置之类的,也尚可,比如ODBC的方式连接MySQL。

②当MySQL 连接服务器时发生”is not allowed to connect to this MySQL server”错误,我们要注意在MySQL的user表中修改host列的localhost为%,即可以远程连接。

做如下操作:

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,user,password from user; --查询USER 表

+-----------+------------------+-------------------------------------------+| host | user | password |

+-----------+------------------+-------------------------------------------+| localhost | root | *MD5加密 |

| ubuntu | root | *MD5加密 |

| 127.0.0.1 | root | *MD5加密 |

| localhost | debian-sys-maint | * MD5加密|

+-----------+------------------+-------------------------------------------+mysql>deletefromuserwhereuser='root'andhost <>'%';--删除多余用户

Query OK, 2rowsaffected (0.00 sec)

mysql>updateusersethost ='%'wherehost='localhost'anduser='root';--更新host

Query OK, 1 row affected (0.00 sec)

Rowsmatched: 1 Changed: 1 Warnings: 0

mysql>selecthost,user,passwordfromuser;

+-----------+------------------+-------------------------------------------+

| host | user | password |

+-----------+------------------+-------------------------------------------+

| % | root | *MD5加密|

| localhost | debian-sys-maint | * MD5加密|

+-----------+------------------+-------------------------------------------+

2 rows in set (0.00 sec)

注:如果在修改User时失误出现以下结果,怎么办?

mysql> select host,user,password from user;

+-----------+------------------+-------------------------------------------+

| host | user | password |

+-----------+------------------+-------------------------------------------+

| ubuntu | root | * MD5加密|

| localhost | debian-sys-maint | * MD5加密|

+-----------+------------------+-------------------------------------------+

2 rows in set (0.00 sec)

此时没有127.0.0.1和localhost主机,所以无法用root用户进行连接,会提示以下错误

~$ mysql -u root -p

Enterpassword:

ERROR 1045 (28000): Access deniedforuser'root'@'localhost'(usingpassword: YES)

则此时只能用系统自带的debian-sys-maint用户登录,修改host。该用户的的登录密码在/etc/mysql/debian.cnf中明文显示。

比如:host=localhost

user=debian-sys-maint

password= 明文密码

socket= /var/run/mysqld/mysqld.sock

basedir= /usr

做如下操作:~$ mysql -u debian-sys-maint -p

Enterpassword:

mysql> use mysql;

mysql>updateusersethost ='%'wherehost='ubuntu';

mysql> exit

~$ sudo /etc/init.d/mysql restart

清理思路,注意操作后需重启服务。

【编辑推荐】

【责任编辑:高圆圆 TEL:(010)68476606】

点赞 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值