記錄于2021-02-19,OS為阿里云輕量應(yīng)用服務(wù)器CentOS 7.3
安裝和啟動(dòng)
安裝mysqlyum install mysql mysql-devel mariadb-server -y
啟動(dòng)mysql服務(wù)systemctl start mariadb
運(yùn)行mysqlmysql
[root@izbp112i9bshiu2ybihp3mz admin]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 30
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
CentOS 6 中安裝mysql的命令是yum install mysql mysql-devel mysql-server -y
CentOS 7 中將mysql-server
替換為mariadb-server
的原因是:
MariaDB數(shù)據(jù)庫(kù)管理系統(tǒng)是MySQL的一個(gè)分支痛垛,主要由開源社區(qū)在維護(hù)刺桃,采用GPL授權(quán)許可粹淋。開發(fā)這個(gè)分支的原因之一是:甲骨文公司收購(gòu)了MySQL后,有將MySQL閉源的潛在風(fēng)險(xiǎn)虏肾,因此社區(qū)采用分支的方式來避開這個(gè)風(fēng)險(xiǎn)廓啊。MariaDB的目的是完全兼容MySQL,包括API和命令行封豪,使之能輕松成為MySQL的代替品谴轮。
防火墻設(shè)置
1.服務(wù)器管理平臺(tái)防火墻
默認(rèn)情況下只有前三條,第四條需要自行添加吹埠。
2.系統(tǒng)防火墻
默認(rèn)情況下第步,防火墻處于關(guān)閉狀態(tài),這是為什么缘琅?難道是存在第一道墻的情況下粘都,這一道意義不大?刷袍?
如果不運(yùn)行系統(tǒng)內(nèi)防火墻翩隧,可以略過此處。
CentOS 7 拋棄了CentOS 6 的iptables.service
使用firewalld.service
控制防火墻呻纹,使用systemctl
來管理此服務(wù)堆生。當(dāng)然可以通過yum -y install iptables-services
來安裝iptables.service
专缠,安裝成功后兩個(gè)服務(wù)可以同時(shí)關(guān)閉,但同一時(shí)間只能開啟一個(gè)服務(wù)淑仆,并且兩個(gè)服務(wù)的配置信息不會(huì)相互干擾涝婉。比如開啟iptables.service
(此服務(wù)開啟3306端口)的情況下,開啟firewalld.service
(此服務(wù)關(guān)閉3306端口)蔗怠,會(huì)先關(guān)閉iptables.service
再打開firewalld.service
墩弯,此時(shí)系統(tǒng)3306端口是關(guān)閉的;
firewall-cmd --zone=public --add-port=3306/tcp --permanent
打開3306端口
firewall-cmd --reload
重載防火墻配置
設(shè)置mysql數(shù)據(jù)庫(kù)權(quán)限(允許其他服務(wù)器連接數(shù)據(jù)庫(kù))
GRANT ALL PRIVILEGES ON *.* TO 'root'@'33.33.33.33' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
[root@izbp112i9bshiu2ybihp3mz admin]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 31
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'33.33.33.33' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
此時(shí)寞射,就可以在ip地址為33.33.33.33的電腦上使用賬戶(root)密碼(mypassword)進(jìn)行連接了