MySQL - Centos7安裝配置MariaDB10.3

生成配置

MariaDB Repository Configuration Tool 選擇系統版本以及需要安裝的mariadb版本。將生成的內容將生成的內容保存至/etc/yum.repos.d/mariadb.repo

例如我選擇的是系統版本是centos7 (x86_64),要安裝的是10.3[old stable]版本。

# MariaDB 10.3 CentOS repository list - created 2021-01-21 06:32 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

更換源

執行以下命令替換源地址

sudo sed -i 's#yum\.mariadb\.org#mirrors.ustc.edu.cn/mariadb/yum#' /etc/yum.repos.d/mariadb.repo
# 建議使用 HTTPS
sudo sed -i 's#http://mirrors\.ustc\.edu\.cn#https://mirrors.ustc.edu.cn#g' /etc/yum.repos.d/mariadb.repo

安裝

sudo yum install MariaDB-server MariaDB-client

配置

  1. 啓動服務並設爲開機自啓
systemctl start mariadb
systemctl enable mariadb
  1. 設置密碼

執行mysql_secure_installation命令進行root密碼的設置

mysql_secure_installation #設置root密碼等相關

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。或者重啓服務也許
  1. 設置字符集

/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

/etc/my.cnf.d/client.cnf文件[client]標籤下添加

default-character-set=utf8

/etc/my.cnf.d/mysql-clients.cnf文件[mysql]標籤下添加

default-character-set=utf8
  1. 重啓服務
systemctl restart mariadb

驗證

  1. 查看mariadb版本
[root@localhost ~]# mysql -uroot -p

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.3.27-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)]> 

安裝版本爲10.3.27🆗

  1. 查看字符集相關配置
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 |

參考

centos7 安裝Mariadb

MariaDB 源使用幫助

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