Home > Database > Mysql Tutorial > mysql设置远程访问数据库的多种方法_MySQL

mysql设置远程访问数据库的多种方法_MySQL

WBOY
Release: 2016-06-01 13:25:43
Original
1046 people have browsed it

bitsCN.com

可能是IP没设置好

问题:MySQL权限设置正确,但仍无法远程访问。通过telnet发现3306端口未打开。

分析:MySQL默认只绑定127.0.0.1,即:只有在本机才能访问3306端口。

解决:找到MySQL配置文件,搜索“bind-address”,找到这一行:

bind-address          = 127.0.0.1 在前面加一个#,注释掉这一行,保存,重启MySQL。再通过远程访问就可以了,telnet可以发现端口也打开了。

例我们配置

1. 确保skip-networking被删除或者屏蔽,否则不支持TCP/IP 访问
2. 增加行bind-address = 65.55.55.2,替代65.55.55.2 为你的服务器地址

修改后,配置为:


[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/English
bind-address = 65.55.55.2
# skip-networking
....
..

保存并关闭配置文件
重启mysql服务器:# /etc/init.d/mysql restart


如果上面办法没有用我们可以通用mysql命令模式进行设置

1。 改表法。

可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"


CODE:mysql -u root -p123
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;

2. 授权法。

例如,你想kevin使用mypassword从任何主机连接到mysql服务器的话。
GRANT ALL PRIVILEGES ON *.* TO 'kevin'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
如果你想允许用户kevin从ip为192.168.101.234的主机连接到mysql服务器,并使用mypassword作为密码


GRANT ALL PRIVILEGES ON *.* TO 'kevin'@'192.168.101.234' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

注意了,如果是linux系统防火墙也很重要哦


/* 关闭防火墙 */
service iptables stop
/* 开启防火墙 */
service iptables start
/* 默认关闭防火墙 */
chkconfig iptables off

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template