默認上MariaDB的包并沒有在Ubuntu倉庫中。要安裝MariaDB,我們要設置MariaDB倉庫。
sudo apt-get install software-properties-common
sudo apt-keyadv--recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirrors.neusoft.edu.cn/mariadb/repo/10.3/ubuntu xenial main'
2.3 安裝MariaDB
sudo apt update?
sudo apt install mariadb-server
在安裝中,你會被要求設置MariaDB的root密碼。
三、運行
3.1 通過命令行連接MariaDB
mysql -u root -p
3.2 MariaDB 服務啟動與停止
sudo/etc/init.d/mysql stop
sudo/etc/init.d/mysql start
四、配置
4.1 允許遠程訪問
如果Ubuntu有設置防火墻或者iptables規則的話,請允許指定端口號訪問
判斷3306端口是否打開
4.1.1 使用 netstat命令查看3306端口狀態
netstat-an | grep3306
從上面結果可以看出3306端口只在IP?127.0.0.1?上監聽,所以拒絕了其他IP的訪問。
解決方案:
修改/etc/mysql/my.cnf文件。找到下面內容:
# Instead of skip-networking thed efault 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檢測。
使用命令測試
mysql -h192.168.0.xxx -u root -p
Enter password:ERROR1130(HY000): Host'192.168.0.xxx'isnotallowedtoconnecttothis MariaDB server
解決方案:需要將用戶權限分配給各個遠程用戶
登錄mysql服務器,使用grant命令分配權限
grant all on *.* to '用戶名'@'%' identified by '密碼';
例子:grant all on *.* 'root'@'%' identified by '123456';
這樣即可遠程訪問了。