CentOS7下yum安裝MariaDB與簡單配置

CentOS7下yum安裝MariaDB與簡單配置

開始之前要確保已經安裝yum並且配置好相關的源。

一、 安裝命令:

yum -y install mariadb mariadb-server

二、啓動MariaDB

systemctl start mariadb

三、 設置開機啓動

systemctl enable mariadb

四、相關配置

mysql_secure_installation

1. 設置密碼

Enter current password for root (enter for none): #直接回車就行
Set root password? [Y/n] y # 設置密碼
New password: 
Re-enter new password: 


Remove anonymous users? [Y/n] # 是否刪除匿名用戶,刪除就行

Disallow root login remotely? [Y/n] n # 是否禁止root遠程登錄,N

Remove test database and access to it? [Y/n] #  是否刪除測試表,Y

Reload privilege tables now? [Y/n] # 是否重新加載權限表,Y


Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

2. 登錄

mysql -uroot -proot

3. 配置MariaDB的字符集

a. 查看數據庫字符集

show variables like "%character%";show variables like "%collation%";

顯示如下

+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | utf8_general_ci   |
| collation_database   | latin1_swedish_ci |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+

b.修改文件/etc/my.cnf文件

vi /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

c.修改文件 /etc/my.cnf.d/client.cnf

vi /etc/my.cnf.d/client.cnf

在[client]中添加

default-character-set=utf8

d. 修改文件/etc/my.cnf.d/mysql-clients.cnf

vi /etc/my.cnf.d/mysql-clients.cnf

在[mysql]中添加

default-character-set=utf8

e.重啓MariaDB

systemctl restart mariadb

f.查看修改後的字符集

進入數據庫

mysql -uroot -proot
show variables like "%character%";show variables like "%collation%";
MariaDB [(none)]> show variables like "%character%";show variables like "%collation%";
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database   | utf8_unicode_ci |
| collation_server     | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

4. 添加用戶,設置權限

a.創建用戶命令

MariaDB [(none)]> create user inspur@localhost identified by 'inspur';

b. 授權

grant all privileges on *.* to inspur@'localhost' identified by 'inspur';

b.授予外網登錄權限

grant all privileges on *.* to root@'%' identified by 'inspur';

參考文章:

CentOS 7.0 使用 yum 安裝 MariaDB 與 MariaDB 的簡單配置

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章