1. 程式人生 > >CentOS7下使用yum安裝MariaDB + 解決yum安裝MariaDB 速度巨慢的問題

CentOS7下使用yum安裝MariaDB + 解決yum安裝MariaDB 速度巨慢的問題

CentOS7下使用yum安裝MariaDB

https://www.cnblogs.com/river2005/p/6813618.html

解決yum安裝MariaDB 速度巨慢的問題

https://blog.csdn.net/q297896911/article/details/80603377

 

 

 

============================================================

CentOS 6 或早期的版本中提供的是 MySQL 的伺服器/客戶端安裝包,但 CentOS 7 已使用了 MariaDB 替代了預設的 MySQL。MariaDB資料庫管理系統是MySQL的一個分支,主要由開源社群在維護,採用GPL授權許可 MariaDB的目的是完全相容MySQL,包括API和命令列,使之能輕鬆成為MySQL的代替品。

Linux下安裝MariaDB官方文件參見:https://mariadb.com/kb/zh-cn/installing-mariadb-with-yum/

全部刪除MySQL/MariaDB

MySQL 已經不再包含在 CentOS 7 的源中,而改用了 MariaDB;

1.使用rpm -qa | grep mariadb搜尋 MariaDB 現有的包:

如果存在,使用rpm -e --nodeps mariadb-*全部刪除:

[[email protected] ~]# rpm -qa | grep mariadb
mariadb-server-5.5.52-1.el7.x86_64
mariadb-libs-5.5.52-1.el7.x86_64
[
[email protected]
~]# rpm -e mysql-* 錯誤:未安裝軟體包 mysql-*

 

2.使用rpm -qa | grep mariadb搜尋 MariaDB 現有的包:

如果存在,使用yum remove mysql mysql-server mysql-libs compat-mysql51全部刪除;

複製程式碼

[[email protected] ~]# yum remove mysql mysql-server mysql-libs compat-mysql51
已載入外掛:fastestmirror, langpacks
引數 mysql 沒有匹配
引數 mysql-server 沒有匹配
引數 compat-mysql51 沒有匹配
正在解決依賴關係
--> 正在檢查事務
---> 軟體包 mariadb-libs.x86_64.1.5.5.52-1.el7 將被 刪除
--> 正在處理依賴關係 libmysqlclient.so.18()(64bit),它被軟體包 perl-DBD-MySQL-4.023-5.el7.x86_64 需要
--> 正在處理依賴關係 libmysqlclient.so.18()(64bit),它被軟體包 2:postfix-2.10.1-6.el7.x86_64 需要
--> 正在處理依賴關係 libmysqlclient.so.18()(64bit),它被軟體包 1:qt-mysql-4.8.5-13.el7.x86_64 需要..........

複製程式碼

複製程式碼

刪除:
  mariadb-libs.x86_64 1:5.5.52-1.el7                                            

作為依賴被刪除:
  akonadi-mysql.x86_64 0:1.9.2-4.el7     mariadb-server.x86_64 1:5.5.52-1.el7   
  perl-DBD-MySQL.x86_64 0:4.023-5.el7    postfix.x86_64 2:2.10.1-6.el7          
  qt-mysql.x86_64 1:4.8.5-13.el7        

完畢!
[[email protected] ~]# rpm -qa|grep mariadb
[[email protected] ~]#

複製程式碼

3.開始新的安裝, 建立MariaDB.repo檔案

vi /etc/yum.repos.d/MariaDB.repo

插入以下內容:

複製程式碼

# MariaDB 10.2.4 CentOS repository list - created 2017-05-05 16:13 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

複製程式碼

系統及版本選擇:https://downloads.mariadb.org/mariadb/repositories/#mirror=tuna

4.執行安裝命令安裝MariaDB

複製程式碼

[[email protected] ~]# yum -y install MariaDB-server MariaDB-client
已載入外掛:fastestmirror, langpacks
mariadb                                                  | 2.9 kB     00:00     
mariadb/primary_db                                         |  18 kB   00:09     
Determining fastest mirrors
 * base: mirrors.btte.net
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.zju.edu.cn
正在解決依賴關係
--> 正在檢查事務
---> 軟體包 MariaDB-client.x86_64.0.10.2.4-1.el7.centos 將被 安裝
--> 正在處理依賴關係 MariaDB-common,它被軟體包 MariaDB-client-10.2.4-1.el7.centos.x86_64 需要
---> 軟體包 MariaDB-server.x86_64.0.10.2.4-1.el7.centos 將被 安裝
--> 正在處理依賴關係 galera,它被軟體包 MariaDB-server-10.2.4-1.el7.centos.x86_64 需要
--> 正在處理依賴關係 libjemalloc.so.1()(64bit),它被軟體包 MariaDB-server-10.2.4-1.el7.centos.x86_64 需要
--> 正在檢查事務
---> 軟體包 MariaDB-common.x86_64.0.10.2.4-1.el7.centos 將被 安裝
--> 正在處理依賴關係 MariaDB-compat,它被軟體包 MariaDB-common-10.2.4-1.el7.centos.x86_64 需要
---> 軟體包 galera.x86_64.0.25.3.19-1.rhel7.el7.centos 將被 安裝
---> 軟體包 jemalloc.x86_64.0.3.6.0-1.el7 將被 安裝
--> 正在檢查事務
---> 軟體包 MariaDB-compat.x86_64.0.10.2.4-1.el7.centos 將被 安裝
--> 解決依賴關係完成

依賴關係解決

================================================================================
 Package            架構       版本                           源           大小
================================================================================
正在安裝:
 MariaDB-client     x86_64     10.2.4-1.el7.centos            mariadb      48 M
 MariaDB-server     x86_64     10.2.4-1.el7.centos            mariadb     113 M
為依賴而安裝:
 MariaDB-common     x86_64     10.2.4-1.el7.centos            mariadb     104 k
 MariaDB-compat     x86_64     10.2.4-1.el7.centos            mariadb     2.8 M
 galera             x86_64     25.3.19-1.rhel7.el7.centos     mariadb     8.0 M
 jemalloc           x86_64     3.6.0-1.el7                    mariadb     104 k

事務概要
================================================================================
安裝  2 軟體包 (+4 依賴軟體包)
....

複製程式碼

 

首先下載安裝包,然後進行自動安裝,安裝成功之後啟動MariaDB服務。

systemctl start mariadb #啟動服務
systemctl enable mariadb #設定開機啟動
systemctl restart mariadb #重新啟動
systemctl stop mariadb.service #停止MariaDB

5.登入到資料庫

  用mysql -uroot命令登入到MariaDB,此時root賬戶的密碼為空。

6.進行MariaDB的相關簡單配置,使用mysql_secure_installation命令進行配置。

mysql_secure_installation

 

 首先是設定密碼,會提示先輸入密碼

Enter current password for root (enter for none):<–初次執行直接回車

設定密碼

Set root password? [Y/n] <– 是否設定root使用者密碼,輸入y並回車或直接回車
New password: <– 設定root使用者的密碼
Re-enter new password: <– 再輸入一次你設定的密碼

其他配置

Remove anonymous users? [Y/n] <– 是否刪除匿名使用者,回車

Disallow root login remotely? [Y/n] <–是否禁止root遠端登入,回車,

Remove test database and access to it? [Y/n] <– 是否刪除test資料庫,回車

Reload privilege tables now? [Y/n] <– 是否重新載入許可權表,回車

初始化MariaDB完成,接下來測試登入

mysql -uroot -ppassword

完成。

 7.配置MariaDB的字符集

  檢視/etc/my.cnf檔案內容,其中包含一句!includedir /etc/my.cnf.d 說明在該配置檔案中引入/etc/my.cnf.d 目錄下的配置檔案。

  1)使用vi server.cnf命令編輯server.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 目錄下無server.cnf檔案,則直接在/etc/my.cnf檔案的[mysqld]標籤下新增以上內容。

2)檔案/etc/my.cnf.d/client.cnf

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

在[client]中新增

default-character-set=utf8

3)檔案/etc/my.cnf.d/mysql-clients.cnf

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

在[mysql]中新增

default-character-set=utf8

 全部配置完成,重啟mariadb

systemctl restart mariadb

之後進入MariaDB檢視字符集

mysql> 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)

複製程式碼

字符集配置完成。

8. 新增使用者,設定許可權

建立使用者命令

mysql>create user [email protected] identified by 'password';

直接建立使用者並授權的命令

mysql>grant all on *.* to [email protected] indentified by 'password';

授予外網登陸許可權 

mysql>grant all privileges on *.* to [email protected]'%' identified by 'password';

授予許可權並且可以授權

mysql>grant all privileges on *.* to [email protected]'hostname' identified by 'password' with grant option;

複製程式碼

MariaDB [mysql]> select host,user,password from user;
+-----------------------+-------+------------------------+
| host                  | user  | password               |
+-----------------------+-------+------------------------+
| localhost             | root  | *E87F9354F7E889A65E... |
| localhost.localdomain | root  | *E87F9354F7E889A65E... |
| 127.0.0.1             | root  | *E87F9354F7E889A65E... |
| ::1                   | root  | *E87F9354F7E889A65E... |
| localhost             |       |                        |
| localhost.localdomain |       |                        |
+-----------------------+-------+------------------------+
7 rows in set (0.00 sec)

複製程式碼

 

簡單的使用者和許可權配置基本就這樣了。

其中只授予部分許可權把 其中 all privileges或者all改為select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file其中一部分。

Linux系統教程:如何檢查MariaDB服務端版本  http://www.linuxidc.com/Linux/2015-08/122382.htm

MariaDB Proxy讀寫分離的實現 http://www.linuxidc.com/Linux/2014-05/101306.htm

Linux下編譯安裝配置MariaDB資料庫的方法 http://www.linuxidc.com/Linux/2014-11/109049.htm

CentOS系統使用yum安裝MariaDB資料庫 http://www.linuxidc.com/Linux/2014-11/109048.htm

安裝MariaDB與MySQL並存 http://www.linuxidc.com/Linux/2014-11/109047.htm

 

===============================================================================

CentOS 6 或早期的版本中提供的是 MySQL 的伺服器/客戶端安裝包,但 CentOS 7 已使用了 MariaDB 替代了預設的 MySQL。MariaDB資料庫管理系統是MySQL的一個分支,主要由開源社群在維護,採用GPL授權許可 MariaDB的目的是完全相容MySQL,包括API和命令列,使之能輕鬆成為MySQL的代替品。

Linux下安裝MariaDB官方文件參見:https://mariadb.com/kb/zh-cn/installing-mariadb-with-yum/

全部刪除MySQL/MariaDB

MySQL 已經不再包含在 CentOS 7 的源中,而改用了 MariaDB;

1.使用rpm -qa | grep mariadb搜尋 MariaDB 現有的包:

如果存在,使用rpm -e --nodeps mariadb-*全部刪除:

[[email protected] ~]# rpm -qa | grep mariadb
mariadb-server-5.5.52-1.el7.x86_64
mariadb-libs-5.5.52-1.el7.x86_64
[[email protected] ~]# rpm -e mysql-*
錯誤:未安裝軟體包 mysql-* 

 

2.使用rpm -qa | grep mariadb搜尋 MariaDB 現有的包:

如果存在,使用yum remove mysql mysql-server mysql-libs compat-mysql51全部刪除;

複製程式碼

[[email protected] ~]# yum remove mysql mysql-server mysql-libs compat-mysql51
已載入外掛:fastestmirror, langpacks
引數 mysql 沒有匹配
引數 mysql-server 沒有匹配
引數 compat-mysql51 沒有匹配
正在解決依賴關係
--> 正在檢查事務
---> 軟體包 mariadb-libs.x86_64.1.5.5.52-1.el7 將被 刪除
--> 正在處理依賴關係 libmysqlclient.so.18()(64bit),它被軟體包 perl-DBD-MySQL-4.023-5.el7.x86_64 需要
--> 正在處理依賴關係 libmysqlclient.so.18()(64bit),它被軟體包 2:postfix-2.10.1-6.el7.x86_64 需要
--> 正在處理依賴關係 libmysqlclient.so.18()(64bit),它被軟體包 1:qt-mysql-4.8.5-13.el7.x86_64 需要..........

複製程式碼

複製程式碼

刪除:
  mariadb-libs.x86_64 1:5.5.52-1.el7                                            

作為依賴被刪除:
  akonadi-mysql.x86_64 0:1.9.2-4.el7     mariadb-server.x86_64 1:5.5.52-1.el7   
  perl-DBD-MySQL.x86_64 0:4.023-5.el7    postfix.x86_64 2:2.10.1-6.el7          
  qt-mysql.x86_64 1:4.8.5-13.el7        

完畢!
[[email protected] ~]# rpm -qa|grep mariadb
[[email protected] ~]#

複製程式碼

3.開始新的安裝, 建立MariaDB.repo檔案

vi /etc/yum.repos.d/MariaDB.repo

插入以下內容:

複製程式碼

# MariaDB 10.2.4 CentOS repository list - created 2017-05-05 16:13 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

複製程式碼

系統及版本選擇:https://downloads.mariadb.org/mariadb/repositories/#mirror=tuna

4.執行安裝命令安裝MariaDB

複製程式碼

[[email protected] ~]# yum -y install MariaDB-server MariaDB-client
已載入外掛:fastestmirror, langpacks
mariadb                                                  | 2.9 kB     00:00     
mariadb/primary_db                                         |  18 kB   00:09     
Determining fastest mirrors
 * base: mirrors.btte.net
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.zju.edu.cn
正在解決依賴關係
--> 正在檢查事務
---> 軟體包 MariaDB-client.x86_64.0.10.2.4-1.el7.centos 將被 安裝
--> 正在處理依賴關係 MariaDB-common,它被軟體包 MariaDB-client-10.2.4-1.el7.centos.x86_64 需要
---> 軟體包 MariaDB-server.x86_64.0.10.2.4-1.el7.centos 將被 安裝
--> 正在處理依賴關係 galera,它被軟體包 MariaDB-server-10.2.4-1.el7.centos.x86_64 需要
--> 正在處理依賴關係 libjemalloc.so.1()(64bit),它被軟體包 MariaDB-server-10.2.4-1.el7.centos.x86_64 需要
--> 正在檢查事務
---> 軟體包 MariaDB-common.x86_64.0.10.2.4-1.el7.centos 將被 安裝
--> 正在處理依賴關係 MariaDB-compat,它被軟體包 MariaDB-common-10.2.4-1.el7.centos.x86_64 需要
---> 軟體包 galera.x86_64.0.25.3.19-1.rhel7.el7.centos 將被 安裝
---> 軟體包 jemalloc.x86_64.0.3.6.0-1.el7 將被 安裝
--> 正在檢查事務
---> 軟體包 MariaDB-compat.x86_64.0.10.2.4-1.el7.centos 將被 安裝
--> 解決依賴關係完成

依賴關係解決

================================================================================
 Package            架構       版本                           源           大小
================================================================================
正在安裝:
 MariaDB-client     x86_64     10.2.4-1.el7.centos            mariadb      48 M
 MariaDB-server     x86_64     10.2.4-1.el7.centos            mariadb     113 M
為依賴而安裝:
 MariaDB-common     x86_64     10.2.4-1.el7.centos            mariadb     104 k
 MariaDB-compat     x86_64     10.2.4-1.el7.centos            mariadb     2.8 M
 galera             x86_64     25.3.19-1.rhel7.el7.centos     mariadb     8.0 M
 jemalloc           x86_64     3.6.0-1.el7                    mariadb     104 k

事務概要
================================================================================
安裝  2 軟體包 (+4 依賴軟體包)
....

複製程式碼

 

首先下載安裝包,然後進行自動安裝,安裝成功之後啟動MariaDB服務。

systemctl start mariadb #啟動服務
systemctl enable mariadb #設定開機啟動
systemctl restart mariadb #重新啟動
systemctl stop mariadb.service #停止MariaDB

5.登入到資料庫

  用mysql -uroot命令登入到MariaDB,此時root賬戶的密碼為空。

6.進行MariaDB的相關簡單配置,使用mysql_secure_installation命令進行配置。

mysql_secure_installation

 

 首先是設定密碼,會提示先輸入密碼

Enter current password for root (enter for none):<–初次執行直接回車

設定密碼

Set root password? [Y/n] <– 是否設定root使用者密碼,輸入y並回車或直接回車
New password: <– 設定root使用者的密碼
Re-enter new password: <– 再輸入一次你設定的密碼

其他配置

Remove anonymous users? [Y/n] <– 是否刪除匿名使用者,回車

Disallow root login remotely? [Y/n] <–是否禁止root遠端登入,回車,

Remove test database and access to it? [Y/n] <– 是否刪除test資料庫,回車

Reload privilege tables now? [Y/n] <– 是否重新載入許可權表,回車

初始化MariaDB完成,接下來測試登入

mysql -uroot -ppassword

完成。

 7.配置MariaDB的字符集

  檢視/etc/my.cnf檔案內容,其中包含一句!includedir /etc/my.cnf.d 說明在該配置檔案中引入/etc/my.cnf.d 目錄下的配置檔案。

  1)使用vi server.cnf命令編輯server.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 目錄下無server.cnf檔案,則直接在/etc/my.cnf檔案的[mysqld]標籤下新增以上內容。

2)檔案/etc/my.cnf.d/client.cnf

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

在[client]中新增

default-character-set=utf8

3)檔案/etc/my.cnf.d/mysql-clients.cnf

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

在[mysql]中新增

default-character-set=utf8

 全部配置完成,重啟mariadb

systemctl restart mariadb

之後進入MariaDB檢視字符集

mysql> 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)

複製程式碼

字符集配置完成。

8. 新增使用者,設定許可權

建立使用者命令

mysql>create user [email protected] identified by 'password';

直接建立使用者並授權的命令

mysql>grant all on *.* to [email protected] indentified by 'password';

授予外網登陸許可權 

mysql>grant all privileges on *.* to [email protected]'%' identified by 'password';

授予許可權並且可以授權

mysql>grant all privileges on *.* to [email protected]'hostname' identified by 'password' with grant option;

複製程式碼

MariaDB [mysql]> select host,user,password from user;
+-----------------------+-------+------------------------+
| host                  | user  | password               |
+-----------------------+-------+------------------------+
| localhost             | root  | *E87F9354F7E889A65E... |
| localhost.localdomain | root  | *E87F9354F7E889A65E... |
| 127.0.0.1             | root  | *E87F9354F7E889A65E... |
| ::1                   | root  | *E87F9354F7E889A65E... |
| localhost             |       |                        |
| localhost.localdomain |       |                        |
+-----------------------+-------+------------------------+
7 rows in set (0.00 sec)

複製程式碼

 

簡單的使用者和許可權配置基本就這樣了。

其中只授予部分許可權把 其中 all privileges或者all改為select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file其中一部分。

Linux系統教程:如何檢查MariaDB服務端版本  http://www.linuxidc.com/Linux/2015-08/122382.htm

MariaDB Proxy讀寫分離的實現 http://www.linuxidc.com/Linux/2014-05/101306.htm

Linux下編譯安裝配置MariaDB資料庫的方法 http://www.linuxidc.com/Linux/2014-11/109049.htm

CentOS系統使用yum安裝MariaDB資料庫 http://www.linuxidc.com/Linux/2014-11/109048.htm

安裝MariaDB與MySQL並存 http://www.linuxidc.com/Linux/2014-11/109047.htm

 

 

 

===========================================================

建立/etc/yum.repos.d/MariaDB.repo檔案,這裡用到了剛剛釋出正式版的10.3.7版本

首先看官方的映象  發現MariaDB下載很慢  幾十Kb  簡直要崩潰有木有

 
  1. [mariadb]

  2. name = MariaDB

  3. baseurl = http://yum.mariadb.org/10.3.7/centos7-amd64/

  4. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

  5. gpgcheck=1

接下來 把程式碼換一下,咱們使用阿里雲的映象

  •  
    1. [mariadb]

    2. name = MariaDB

    3. baseurl = http://mirrors.ustc.edu.cn/mariadb/yum/10.3/centos7-amd64/

    4. gpgkey=http://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB

    5. gpgcheck=1

    奇蹟發生了   網速嗖嗖的有木有