默認上MariaDB的包並沒有在Ubuntu倉庫中。要安裝MariaDB,我們首先要設置MariaDB倉庫。
設置 MariaDB 倉庫
- $ sudo apt-get install software-properties-common
- $ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
- $ sudo add-apt-repository 'deb http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.0/ubuntu trusty main'
安裝 MariaDB :
- $ sudo apt-get update
- $ sudo apt-get install mariadb-server
在安裝中,你會被要求設置MariaDB的root密碼。
從命令行連接到MariaDB :
- linuxtechi@mail:~$ mysql -uroot -p
- Enter password:
- Welcome to the MariaDB monitor. Commands end with ; or \g.
- Your MariaDB connection id is 40
- Server version: 10.0.14-MariaDB-1~trusty-log mariadb.org binary distribution
- Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- MariaDB [(none)]>
MariaDB 服務
- $ sudo /etc/init.d/mysql stop
- $ sudo /etc/init.d/mysql start
以上只是在Ubuntu上裝完MariaDB,下面要設置MariaDB允許遠程訪問
1. 如果Ubuntu有設置防火牆或者iptables規則的話,請自行打開
2. 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,建議注釋掉。
重新啟動后,重新使用netstat檢測:
~# netstat -an | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
3. 現在使用下面命令測試:
~# mysql -h 192.168.0.101 -u root -p
Enter password:
ERROR 1130 (00000): Host 'Ubuntu-Fvlo.Server' is not allowed to connect to this MySQL server
結果出乎意料,還是不行。
解決方法:原來還需要把用戶權限分配各遠程用戶。
登錄到mysql服務器,使用grant命令分配權限
mysql> grant all on *.* to 你的用戶名如root@'%' identified by '你的密碼';
完成后使用mysql命令連接,提示成功,為了確保正確可以再遠程登陸測試一下。