MYSQL 使能远程访问

MYSQL默认只能本机访问,为了在其他主机上访问MYSQL需要手动配置。
首先需要为非本地(localhost)主机配置权限,然后修改MYSQL配置文件打开mysql的远程访问端口。
step1.  以root身份登入mysql
pi@raspberrypi ~ $mysql -u root -p
step2. 
##root使用123456从任何主机连接到mysql服务器
mysql>  grant all privileges on *.* to root@”%” identified by “123456″;
step3.
mysql> FLUSH PRIVILEGES;  ##使修改生效
##验证是否修改成功。
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host, user from user;
+————-+———————+
| host           | user                   |
+————-+———————+
| %               | root                   |
| 127.0.0.1    | root                   | 
| localhost    |                           |
| localhost    | debian-sys-maint |
| localhost    | root                    |
| raspberrypi |                          |
| raspberrypi | root                   |
+————-+———————+
7 rows in set (0.00 sec)

step4.打开mysql的远程访问端口
pi@raspberrypi ~ $  netstat -ant | grep 3306
tcp        0      0 127.0.0.1:3306    0.0.0.0:*      LISTEN
从上面可以看出,mysql的3306端口只是监听本地的连接,这样就阻碍了外部IP对该数据库的访问,修改的办法其实很简单,进入到mysql的配置文件所在目录(/etc/mysql/my.cnf)下,找到文件中的如下内容:
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address   = 127.0.0.1  ##注释掉这一行

重启mysql

pi@raspberrypi ~ $  sudo /etc/init.d/mysql restart

转载于:https://my.oschina.net/felixliang/blog/155948

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值