centos7默認(rèn)支持的數(shù)據(jù)庫是mariadb,mariadb支持mysql的所有功能,安裝過程如下:
1、檢查是否已經(jīng)安裝mariadb或者mysql,如有全部刪除:
rpm -qa|grep mariadb
rpm -qa|grep mysql
rpm -e mariadb
rpm -e mysql
注:rpm -e xxx卸載會(huì)檢查xxx是否有依賴,如有則會(huì)提示無法刪除,rpm -e --nodeps xxx卸載不會(huì)檢查依賴,只刪除xxx本身;yum -y remove xxx則會(huì)刪除xxx及其所有依賴
2、安裝:
(1)創(chuàng)建MariaDB.repo文件:
vim /etc/yum.repos.d/MariaDB.repo
在MariaDB.repo文件中添加如下內(nèi)容:
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
(2)直接yum安裝:
yum -y install mariadb mariadb-server?
3、安裝成功后啟動(dòng)mariadb:
systemctl start mariadb #啟動(dòng)服務(wù)
systemctl enable mariadb #設(shè)置開機(jī)啟動(dòng)
systemctl restart mariadb #重新啟動(dòng)
systemctl stop mariadb.service #停止MariaDB
4、登陸:
mysql -uroot -p
初始密碼為空
5、mariadb進(jìn)行簡單配置:
mysql_secure_installation
設(shè)置密碼
Set root password? [Y/n]?<– 是否設(shè)置root用戶密碼,輸入y并回車或直接回車
New password:<– 設(shè)置root用戶的密碼
Re-enter new password:?<– 再輸入一次你設(shè)置的密碼
其他配置
Remove anonymous users? [Y/n]?<– 是否刪除匿名用戶,回車
Disallow root login remotely? [Y/n]?<–是否禁止root遠(yuǎn)程登錄,回車,
Remove test database and access to it? [Y/n]?<– 是否刪除test數(shù)據(jù)庫,回車
Reload privilege tables now? [Y/n]?<– 是否重新加載權(quán)限表,回車
接下來就可以通過設(shè)置的密碼進(jìn)行登陸
6、設(shè)置字符集:
查看/etc/my.cnf中包含“!includedir /etc/my.cnf.d”,說明說明在my.cnf中引入my.cnf.d中的配置,具體配置在my.cnf.d下可以進(jìn)行設(shè)置,接下來打開/etc/my.cnf.d/server.cnf,在[mysqld]下添加如下關(guān)于字符集的配置內(nèi)容:
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
注意:如果沒有server.cnf文件,也可以在my.cnf文件中[mysqld]添加如上配置,效果是一樣的
設(shè)置完成后重啟mariadb:
systemctl restart mariadb
進(jìn)入mariadb查看字符集:


7、添加用戶,設(shè)置權(quán)限
(1)創(chuàng)建用戶:
create user username@localhost identified by 'password’
(2)授予所有權(quán)限:
grant all on *.* to username@localhost indentified by 'password';
(3)允許遠(yuǎn)程連接
grant all privileges on *.* to username@'%' identified by 'password';
簡單的用戶和權(quán)限配置基本就這樣了。
其中只授予部分權(quán)限把?其中?all?privileges或者all改為select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file其中一部分