mysql远程连接设置_MySQL 远程连接配置和排

这几天都要和MySQL数据库打交道,而且还是尽量的使用Python MySQLdb来连接管理。yeah...

之前一直都在CentOS下,对MySQL也没深入一直都没出现过数据库不能远程连接的问题。后来转到Ubuntu14.04 之后,还真是有问题了。

先看看CentOS 6.6 下yum安装的MySQL版本:

[root@s1 ~]# mysql --version

mysql Ver14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1

Ubuntu 14.04 apt-get 安装的MySQL版本:

gea@ub1:~$ mysql --version

mysql Ver14.14 Distrib 5.5.44, for debian-linux-gnu (x86_64) using readline 6.3

一、在CentOS 6.6中对MySQL的test1用户赋予所有权限:并且从远程登录:

mysql> grant all privileges on *.* to test1@'%' identified by '123456'with grant option;

Query OK,0 rows affected (0.00 sec)

从远程登录到本机(192.168.10.10)

gea@ub1:~$ mysql -h 192.168.10.10 -u test1 -p

Enter password:

Welcome to the MySQL monitor. Commands end with ;or \g.

可以看到,登录是没有问题的。

二、在Ubuntu 14.04中对MySQL的test1用户赋予所有权限:并且从远程登录:

mysql> grant all privileges on *.* to test1@'%' identified by '123456'with grant option;

Query OK,0 rows affected (0.00 sec)

从远程登录到本机(192.168.10.15)

[root@s1 ~]# mysql-h 192.168.10.15 -u test1 -p

Enter password:

ERROR2003 (HY000): Can't connect to MySQL server on '192.168.10.15' (111)

结果却出现了不能连接的结果。

排除错误:

1)首先从localhost中确定test1能在本机登录:

gea@ub1:~$ mysql -u test1 -p

Enter password:

Welcome to the MySQL monitor. Commands end with ;or \g.

Your MySQL connection idis 36可以登录,没有问题

2)确认3306端口是否已经打开,并且为远程开放:

1.

gea@ub1:~$ netstat-ntlp

(No info could be read for"-p": geteuid()=1000 but you should be root.)

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp0 0 0.0.0.0:22 0.0.0.0:* LISTEN -tcp0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -tcp60 0 :::80 :::* LISTEN -tcp60 0 :::22 :::* LISTEN -

2.

从远程主机telnet 3306端口

C:\Users\Administrator>telnet 192.168.10.15 3306正在连接192.168.10.15...无法打开到主机的连接。 在端口 3306: 连接失败

OK。找到原因了。远程端口未开放。

只需要修改MySQL的配置文件,设置3306端口开放远程连接。

gea@ub1:~$ sudo vim /etc/mysql/my.cnf

找到:

bind-address = 127.0.0.1把这句注释掉。

重启MySQL服务。。。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值