ubuntu 中的mysql server 无法远程连接
2013-06-21 16:38
465 查看
问题:① 提示”Can not connect to mysql error 10061” ,如图1
② 提示”is not allowed to connect to this MySQL server”
对于数据库的远程连接不外乎两方面入手:1、客户端至服务器端的连通性。2、服务器端没有合理配置。当然非要加上客户端也没有配置之类的,也尚可,比如ODBC的方式连接MySQL。-_-!
①当MySQL 连接服务器时发生”Can not connect to mysql error 10061”错误,我们检查/etc/mysql/my.conf文件中的bind-address选项是否设置为服务器的IP,默认为127.0.0.1。
做如下操作:
cl@ubuntu:~$ sudo vi /etc/mysql/my.cnf --修改文本内容
修改bind-address = 127.0.0.1
为 bind-address = 服务器IP
:wq --保存退出
cl@ubuntu:~$ sudo /etc/init.d/mysql restart --重启服务
②当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> delete from user where user='root' and host <> '%'; --删除多余用户
Query OK, 2 rows affected (0.00 sec)
mysql> update user set host ='%' where host='localhost' and user='root'; --更新host
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select host,user,password from user;
+-----------+------------------+-------------------------------------------+
| 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
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: 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
Enter password:
mysql> use mysql;
mysql> update user set host ='%' where host='ubuntu';
mysql> exit
~$ sudo /etc/init.d/mysql restart
清理思路,注意操作后需重启服务
② 提示”is not allowed to connect to this MySQL server”
对于数据库的远程连接不外乎两方面入手:1、客户端至服务器端的连通性。2、服务器端没有合理配置。当然非要加上客户端也没有配置之类的,也尚可,比如ODBC的方式连接MySQL。-_-!
①当MySQL 连接服务器时发生”Can not connect to mysql error 10061”错误,我们检查/etc/mysql/my.conf文件中的bind-address选项是否设置为服务器的IP,默认为127.0.0.1。
做如下操作:
cl@ubuntu:~$ sudo vi /etc/mysql/my.cnf --修改文本内容
修改bind-address = 127.0.0.1
为 bind-address = 服务器IP
:wq --保存退出
cl@ubuntu:~$ sudo /etc/init.d/mysql restart --重启服务
②当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> delete from user where user='root' and host <> '%'; --删除多余用户
Query OK, 2 rows affected (0.00 sec)
mysql> update user set host ='%' where host='localhost' and user='root'; --更新host
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select host,user,password from user;
+-----------+------------------+-------------------------------------------+
| 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
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: 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
Enter password:
mysql> use mysql;
mysql> update user set host ='%' where host='ubuntu';
mysql> exit
~$ sudo /etc/init.d/mysql restart
清理思路,注意操作后需重启服务
相关文章推荐
- 简单介绍ubuntu server与desktop关系以及解决ubuntu server下的mysql无法被远程连接
- 【MySQL错误系列】本地无法远程连接阿里云Ubuntu环境下Mysql数据库cant connect to mysql server on …..(10061)
- Ubuntu Server 中MySQL无法远程连接?
- ubuntu安装mysql后无法远程连接解决方案
- Ubuntu16.04 解决 LNMP 一键安装包 MySQL 无法远程连接的方法
- Ubuntu16.04 server下配置MySQL,并开启远程连接的方法
- 错误代码是1130,ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to connect to this MySQL server 是无法给远程连接的用
- Ubuntu Server 下开启远程连接 MySQL
- Ubuntu Server 下开启远程连接 MySQL
- ubuntu 下无法远程连接Mysql处理
- aws linux服务器,ubuntu,远程连接MySQL,ERROR 2003 (HY000): Can't connect to MySQL server on
- Ubuntu Server 下开启远程连接MySQL
- 远程客户端无法连接ubuntu下Mysql
- ubuntu-server-15.10 mysql 远程连接
- Ubuntu 14.10 下MySQL无法远程连接问题
- Ubuntu16.04 server下配置MySQL,并开启远程连接
- ubuntu server配置mysql并实现远程连接的操作方法
- 无法远程连接ubuntu下的mysql
- ubuntu安装mysql后无法远程连接处理
- 云服务器Ubuntu_Server_16.04.1安装MySQL并开启远程连接的方法