---
title: "error linux  connection to mysql server  on 10065 "
author: "jsjxqjy"
date: "2010-01-08T11:18:02Z"
tags: ["Blog", "Linux", "MySQL", "防火墙"]
categories: ["数据库"]
slug: "error-linux-connection-to-mysql-server-on-10065"
draft: false
lastmod: "2010-01-08T11:23:53Z"
id: 565645
url: "https://jsjxqjy.iteye.com/blog/565645"
---

有的 时候我们为了解决某些自己以前弄过的问题 都想着是重装系统 ，其实这是没有办法才这样的！

 

 

   呵呵！

 

  处理问题的方式告诉我，多在javaeye上 转下 ，问题就好解决了

 

  我的问题是 远程访问linux上 的mysql一直不行，一直报 error  2003 : connection to mysql server  on 10065 我是用的 SQLyog 登陆的

 

 后来在网上查了，

1\.

```
改表法。
可能是你的帐号不允许从远程登陆，只能在localhost。这个时候只要在localhost的那台电脑，登入mysql后，更改 "mysql" 数据库里的 "user" 表里的 "host" 项，从"localhost"改称"%"
mysql -u root -p123
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
```

 

2\. 进入mysql 授予表 数据库 权限

 

```
 授权法。例如，你想 qjy  

使用mypassword从任何主机连接到mysql服务器的话。
GRANT ALL PRIVILEGES ON *.* TO 'qjy'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
要及时生效 ： FLUSH PRIVILEGES
如果你想允许用户kevin从ip为192.168.1.101的主机连接到mysql服务器，并使用mypassword作为密码

GRANT ALL PRIVILEGES ON *.* TO 'qjy'@'192.168.1.101' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
```

 3. 防火墙

 

```
//关闭防火墙 

service iptables stop 
```

 

 

小结 ：

 

   其实1，2都是为了在mysql 的 mysql数据库中的 user表 里面有这样的记录

```
select Host ,User from user where User ='root' and Host ='%'; 
```

 +------+------+  
| Host | User |  
+------+------+  
| %    | root |  
+------+------+

 

意思是 以root 用户登陆 ，在局域网 中 所有的其他主机上都可以访问

 

最后实在不行 关闭防火墙。

 

 以上是个人小结。

大家有兴趣可以看  [http://taink.iteye.com/blog/493639](http://taink.iteye.com/blog/493639)

 

和 [http://taink.iteye.com/blog/493633](http://taink.iteye.com/blog/493633)  2篇文章  作者 taink