---
title: "Mysql从客户端连接服务器连不上的问题"
author: "xdwangiflytek"
date: "2012-08-16T15:24:51Z"
tags: ["MySQL", "客户端远程连接", "访问权限"]
categories: ["数据库"]
slug: "mysql"
draft: false
lastmod: "2012-08-10T10:27:11Z"
id: 1627913
url: "https://xdwangiflytek.iteye.com/blog/1627913"
---

从另一个ip的客户端访问本地的数据库服务器，出现拒绝访问，解决方案如下：

 

查过资料后发现这个问题，一般都会遇到，Mysql数据库跟其他数据库不一样，需要设置权限可以控制哪台机器能访问数据库，能访问哪些表。

 

cmd（管理员身份）--&gt;D:\\Program Files\\MySQL\\MySQL Server 5.5\\bin\\mysql.exe mysql -h localhost -u root -p

 

Enter password: \*\**

 

Welcome to the MySQL monitor. Commands end with ; or \\g.  
Your MySQL connection id is 5  
Server version: 5.1.43-community MySQL Community Server (GPL)

Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement

 

mysql&gt; **grant all privileges on \*.* to 'root'@'%' identified by '123' with grant**  
\-&gt; option ;

 

Query OK, 0 rows affected (0.00 sec)  
意思就是将服务器上的所有资源都给root用户权限，%代表来自不同的IP  
这里需要注意一下要把密码也要带上。通过密码123登录。  
mysql&gt; FLUSH PRIVILEGES ;  
Query OK, 0 rows affected (0.00 sec)  
最后要刷新下权限。

 

这样就从另一个ip上的客户端连接到本地服务器上了。