当前位置:数据库 > MySQL >>

怎么让mysql允许远程连接的方法

方法一,直接利用phpmyadmin在“权限”-》管理中修改用户选择*.*或输入IP地址。

方法二,使用mysql的GRANT命令进行操作

例如:让newuser用户使用newpwd密码从IP:192.168.1.3主机链接到mysql服务器 
 
具体步骤:

 代码如下 复制代码

mysql>GRANT ALL PRIVILEGES ON *.* TO ‘newuser’@’192.168.1.3′ IDENTIFIED BY ‘newpwd’ WITH GRANT OPTION;
mysql>flush privileges;  

完整配置方法

假设我们有:

 代码如下 复制代码
Web-Server : 192.168.1.100 //ubuntu
Mysql-Server : 192.168.1.101 //xp

我们可以按照下面的步骤修改:
1, 登录 Mysql-Server 连接本地 mysql (默认只允许本地连接)

 代码如下 复制代码

Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

C:Documents and Settingskuco>mysql -h localhost -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 13
Server version: 5.1.45-community-log MySQL Community Server (GPL)

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

mysql>

2, 修改 Mysql-Server 用户配置

 代码如下 复制代码

mysql> USE mysql; -- 切换到 mysql DB
Database changed
mysql> SELECT User, Password, Host FROM user; -- 查看现有用户,密码及允许连接的主机
+------+----------+-----------+
| User | Password | Host      |
+------+----------+-----------+
| root |          | localhost |
+------+----------+-----------+
1 row in set (0.00 sec)

mysql> -- 只有一个默认的 root 用户, 密码为空, 只允许 localhost 连接
mysql> -- 下面我们另外添加一个新的 root 用户, 密码为空, 只允许 192.168.1.100 连接
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.100' IDENTIFIED BY '' WITH GRANT OPTION;

mysql> -- 当然我们也可以直接用 UPDATE 更新 root 用户 Host, 但不推荐, SQL如下:
mysql> -- UPDATE user SET Host='192.168.1.100' WHERE User='root' AND Host='localhost' LIMIT 1;


grant 权限名(所有的权限用all) on    库名(*全部).表名(*全部) to  ’要授权的用户名‘@’%'(%表示所有的IP,可以只些一个IP) identified by “密码”;
身份检查使用user表(Host, User和Password)3个范围列执行。服务器只有在user表记录的Host和User列匹配客户端主机名和用户名并且提供了正确的密码时才接受连接。
在user表Host值的指定方法:

 * Host值可以是主机名或IP号,或’localhost’指出本地主机。
 * 你可以在Host列值使用通配符字符“%”和“_”。
 * Host值’%'匹配任何主机名,空Host值等价于’%'。它们的含义与LIKE操作符的模式匹配操作相同。例如,’%'的Host值与所有主机名匹配,而’%.mysql.com’匹配mysql.com域
的所有主机。


3, 修改 Mysql 配置文件 my.ini

 代码如下 复制代码
bind-address = 127.0.0.1

将 bind-address = 127.0.0.1 这一行注释掉, 即修改为:

 代码如下 复制代码
#bind-address = 127.0.0.1

到此 Mysql-Server 端配置就完成了.

4, 连接 Web-Server , 检查一下是否能连上

 代码如下 复制代码

kuco@kuco-desktop:/$ /opt/lampp/bin/mysql -h 192.168.1.101 -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 23
Server version: 5.1.45-community-log MySQL Community Server (GPL)

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

mysql> -- 一切OK

补充:数据库,mysql教程 
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,