Mariadb服務器

因爲ipa服務和mysql的衝突,我就安裝了MariaDB服務器。

MariaDB

MariaDB數據庫管理系統是MySQL的一個分支,主要由開源社區在維護,採用GPL授權許可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能輕鬆成爲MySQL的代替品。在存儲引擎方面,使用XtraDB(英語:XtraDB)來代替MySQL的InnoDB。
MariaDB基於事務的Maria存儲引擎,替換了MySQL的MyISAM存儲引擎,它使用了Percona的 XtraDB,InnoDB的變體,分支的開發者希望提供訪問即將到來的MySQL 5.4 InnoDB性能。這個版本還包括了 PrimeBase XT (PBXT) 和 FederatedX存儲引擎。

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

全部刪除MySQL/MariaDB

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

1.使用rpm -qa | grep mariadb搜索 MariaDB 現有的包:
如果存在,使用rpm -e --nodeps mariadb-*全部刪除:

[root@ipa ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@ipa ~]# rpm -e mysql-*

2.使用rpm -qa | grep mariadb搜索 MariaDB 現有的包:
如果存在,使用yum remove mysql mysql-server mysql-libs compat-mysql51全部刪除;

[root@ipa ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@ipa ~]# yum remove mysql mysql-server mysql-libs compat-mysql51

卸載完畢!

[root@ipa ~]# rpm -qa | grep mariadb
[root@ipa ~]#

3.開始新的安裝, 下載mysql壓縮包並解壓,創建MariaDB.repo文件

[root@ipa ~]# tar -xvf mysql-8.0.15-1.el7.x86_64.rpm-bundle.tar

配置mariadb.repo文件

[root@ipa ~]# vi /etc/yum.repos.d/maraidb.repo
[mariadb]
name=mariadb
baseurl=file:///root/mysql-8.0.15-1.el7.x86_64.rpm-bundle/
gpgcheck=0
[root@ipa ~]# yum makecache
Loaded plugins: fastestmirror, langpacks
dvd                                                      | 3.6 kB     00:00
mariadb                                                  | 2.9 kB     00:00
(1/5): mariadb/filelists_db                                | 112 kB   00:00
(2/5): mariadb/other_db                                    | 6.8 kB   00:00
(3/5): dvd/other_db                                        | 2.5 MB   00:00
(4/5): mariadb/primary_db                                  |  22 kB   00:00
(5/5): dvd/filelists_db                                    | 6.7 MB   00:01
Loading mirror speeds from cached hostfile
        Metadata Cache Created

4.安裝mariadb和mariadb-server

[root@ipa ~]# yum install -y mariadb mariadb-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.56-2.el7 will be installed
---> Package mariadb-server.x86_64 1:5.5.56-2.el7 will be installed
--> Processing Dependency: perl-DBD-MySQL for package: 1:mariadb-server-5.5.56-2.el7.x86_64
--> Running transaction check
---> Package perl-DBD-MySQL.x86_64 0:4.023-5.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch           Version                Repository   Size
================================================================================
Installing:
 mariadb                x86_64         1:5.5.56-2.el7         dvd         8.7 M
 mariadb-server         x86_64         1:5.5.56-2.el7         dvd          11 M
Installing for dependencies:
 perl-DBD-MySQL         x86_64         4.023-5.el7            dvd         140 k

Transaction Summary
================================================================================
Install  2 Packages (+1 Dependent package)

Total download size: 20 M
Installed size: 107 M
Downloading packages:
--------------------------------------------------------------------------------
Total                                               51 MB/s |  20 MB  00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:mariadb-5.5.56-2.el7.x86_64                                1/3
  Installing : perl-DBD-MySQL-4.023-5.el7.x86_64                            2/3
  Installing : 1:mariadb-server-5.5.56-2.el7.x86_64                         3/3
  Verifying  : 1:mariadb-server-5.5.56-2.el7.x86_64                         1/3
  Verifying  : perl-DBD-MySQL-4.023-5.el7.x86_64                            2/3
  Verifying  : 1:mariadb-5.5.56-2.el7.x86_64                                3/3

Installed:
  mariadb.x86_64 1:5.5.56-2.el7       mariadb-server.x86_64 1:5.5.56-2.el7

Dependency Installed:
  perl-DBD-MySQL.x86_64 0:4.023-5.el7

Complete!

5.啓動MariaDB服務

[root@ipa ~]# systemctl start mariadb
[root@ipa ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

[root@ipa ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):		<–初次運行直接回車
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y				<– 是否設置root用戶密碼,輸入y並回車或直接回車
New password:							<– 設置root用戶的密碼
Re-enter new password:					<– 再輸入一次你設置的密碼
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]				<– 是否刪除匿名用戶,回車
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]			<–是否禁止root遠程登錄,回車,
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]		<– 是否刪除test數據庫,回車
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]		<– 是否重新加載權限表,回車
 ... Success!

Cleaning up...

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

Thanks for using MariaDB!
[root@ipa ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> exit
Bye

6.配置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,在[client]中添加

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

[client]
default-character-set=utf8

[client-mariadb]

3)文件/etc/my.cnf.d/mysql-clients.cnf

[root@ipa ~]# vi /etc/my.cnf.d/mysql-clients.cnf
[mysql]
default-character-set=utf8

全部配置完成,重啓mariadb

systemctl restart mariadb

之後進入MariaDB查看字符集

[root@ipa ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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)

MariaDB [(none)]>

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