您好,欢迎访问一九零五行业门户网

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

mysql默认状态是只支持localhost连接,这样远程服务器都输入ip地址去连接你的服务器是不可以的,下面我来介绍怎么让mysql允许远程连接配置方法,有需要的朋友可参考。
方法一,直接利用在“权限”-》管理中修改用户选择*.*或输入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 pass:
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
其它类似信息

推荐信息