[記錄]linux中安裝mysql且使之能外部訪問

一、安裝命令

sudo apt-get install mysql-server php5-mysql

 First, we need to tell MySQL to create its database directory structure where it will store its information. You can do this by typing:

sudo mysql_install_db

Afterwards, we want to run a simple security script that will remove some dangerous defaults and lock down access to our database system a little bit. Start the interactive script by running:

sudo mysql_secure_installation

二、設置外部訪問

      ~# mysql  -u root -p

     ~# password: **********

     mysql> use mysql;

    mysql> grant all privileges on *.* to 'root'@'%' identified by 'user_password' with option;

   mysql> flush privileges;

三、設置3306端口可以外部訪問

1. 3306端口是不是没有打开?

使用nestat命令查看3306端口状态:

~# netstat -an | grep 3306

tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN

从结果可以看出3306端口只是在IP 127.0.0.1上监听,所以拒绝了其他IP的访问。

解决方法:修改/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

把上面这一行注释掉或者把127.0.0.1换成合适的IP,建议注释掉。

重新启动mysql后

~#: /etc/init.d/mysql restart

重新使用netstat检测:

~# netstat -an | grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN

转载于:https://my.oschina.net/u/1579678/blog/735068

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值