一、安裝命令
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