CentOS 7 安裝 MariaDB
一、使用yum命令直接安裝
[root@localhost ~]# yum install mariadb-server
二、開啟服務
[root@localhost ~]# systemctl start mariadb
三、設置為開機自啟動服務
[root@localhost ~]# systemctl enable mariadb
四、配置(初始密碼等,很重要)
[root@localhost ~]# mysql_secure_installation
解釋一下上面的幾個操作:
Enter current password for root (enter for none): # 輸入資料庫超級管理員root的密碼(注意不是系統root的密碼),第一次進入還沒有設置密碼則直接回車
Set root password? [Y/n] # 設置密碼,y
New password: # 新密碼
Re-enter new password: # 再次輸入密碼
Remove anonymous users? [Y/n] # 移除匿名用戶, y
Disallow root login remotely? [Y/n] # 拒絕root遠程登錄,n,不管y/n,都會拒絕root遠程登錄
Remove test database and access to it? [Y/n] # 刪除test資料庫,y:刪除。n:不刪除,資料庫中會有一個test資料庫,一般不需要
Reload privilege tables now? [Y/n] # 重新加載權限表,y。或者n,然後重啟服務也可以
五、測試是否能夠登錄成功,出現 MariaDB [(none)]> 就表示已經能夠正常登錄使用MariaDB資料庫了
六、下面我們來設置MariaDB默認字符集及編碼
a、修改 /etc/my.cnf 文件,在[mysqld] 標籤下面添加
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
b、修改 /etc/my.cnf.d/client.cnf 文件,在 [client] 標籤下添加
default-character-set=utf8
c、重啟服務
[root@localhost ~]# systemctl restart mariadb
d、進入MariaDB查看字符集
show variables like "%character%";show variables like "%collation%";
七、運程連接配置
1、關閉防火牆或者放開3306埠(可參見:https://www.cnblogs.com/Rozdy/p/11497232.html)
[root@localhost ~]# systemctl stop firewalld
2、修改mysql資料庫中user表,將host = 主機名 的記錄改成 『%』
3、刷新權限或者重啟mariadb服務(二選一,注意:刷新權限表是在資料庫中,重啟服務是在外部命令行中)
5、遠程客戶端連接成功: