MYSQL 开启远程连接问题

来源:互联网 发布:java读取ftp中excel 编辑:程序博客网 时间:2024/06/15 18:54

第一步:

修改 /etc/mysql/my.conf  bind-address的配置, 修改前为:bind-address = 127.0.0.1

愿意是Mysql为了数据安全只允许本机进行范文,现在想要使得远程的机器能够访问MySQL数据库服务,就可以通过改bind-address来实现, 具体的修改方式有两种:

1. bind-address = 0.0.0.0

解释:0.0.0.0为windows对所有未知ip的地址描述,包括网卡dhcp的取得的地址、pppoe的ip,及其它非本机指定ip.

0.0.0.0是全零网络,代表默认网络,帮助路由器发送路由表中无法查询的包。如果设置了全零网络的路由,路由表中无法查询的包都将送到全零网络的路由中去。
2. 直接把bind-address这一行注释掉

#bind-address = 127.0.0.1

 3. /etc/init.d/mysql restart //重新启动mysql服务

第二步:授权用户远程访问
1. /etc/init.d/mysql stop (停止MySQL运行)
2. mysqld_safe --user=mysql --skip-grant-tables --skip-networking &  (以非认证模式启动mysql服务)
3. mysql -u root -p mysql  (登录mysql)
4. 提示输入密码,此时回车就可以了,也就是使用空密码
5. GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'your password here' WITH GRANT OPTION;  (此处是授权从任何机器使用root用户访问mysql数据库)

需要注意的是5 画删除线滴地方,这里是你mysql root的密码,前提是你用root账户连你的mysql,如果此处出错的话,你将收到以下错误。

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

6. quit;
7.  /etc/init.d/mysql restart   //重新启动mysql服务
 
经过这两个步骤,mysql服务器,就可以从远程访问了。




root 密码为空的时候配置文件中下面这句:

skip-grant-tables

GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY '123' WITH GRANT OPTION;

执行这句时候错误:

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY '123' WITH GRANT OPTION;
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

这个时候我们只需要

flush privileges

一下,在添加用户就OK了


原创粉丝点击