1.檢查是否已經(jīng)具有MariaDB相關(guān)安裝,并刪除已有安裝
[root@hadoop01 home]# rpm -qa|grep mariadb #查詢(xún)已安裝包
mariadb-libs-5.5.52-1.el7.x86_64
[root@hadoop01 home]# rpm -e --nodeps mariadb-* # 移除已安裝包
錯(cuò)誤:未安裝軟件包 mariadb-*
[root@hadoop01 home]# yum remove mysql mysql-server mysql-libs compat-mysql51 # 刪除Mysql服務(wù)
已加載插件:fastestmirror, langpacks
參數(shù) mysql 沒(méi)有匹配
參數(shù) mysql-server 沒(méi)有匹配
參數(shù) compat-mysql51 沒(méi)有匹配
正在解決依賴(lài)關(guān)系
--> 正在檢查事務(wù)
---> 軟件包 mariadb-libs.x86_64.1.5.5.52-1.el7 將被 刪除
--> 正在處理依賴(lài)關(guān)系 libmysqlclient.so.18()(64bit)膜廊,它被軟件包 2:postfix-2.10.1-6.el7.x86_64 需要
--> 正在處理依賴(lài)關(guān)系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被軟件包 2:postfix-2.10.1-6.el7.x86_64 需要
--> 正在檢查事務(wù)
---> 軟件包 postfix.x86_64.2.2.10.1-6.el7 將被 刪除
> 解決依賴(lài)關(guān)系完成
▽ase/7/x86_64 | 3.6 kB 00:00:00
extras/7/x86_64 | 3.4 kB 00:00:00
updates/7/x86_64 | 3.4 kB 00:00:00
依賴(lài)關(guān)系解決
============================================================================================================================================================================================================================================
Package 架構(gòu) 版本 源 大小
============================================================================================================================================================================================================================================
正在刪除:
mariadb-libs x86_64 1:5.5.52-1.el7 @anaconda 4.4 M
為依賴(lài)而移除:
postfix x86_64 2:2.10.1-6.el7 @anaconda 12 M
事務(wù)概要
============================================================================================================================================================================================================================================
移除 1 軟件包 (+1 依賴(lài)軟件包)
安裝大小:17 M
是否繼續(xù)?[y/N]:y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在刪除 : 2:postfix-2.10.1-6.el7.x86_64 1/2
正在刪除 : 1:mariadb-libs-5.5.52-1.el7.x86_64 2/2
驗(yàn)證中 : 2:postfix-2.10.1-6.el7.x86_64 1/2
驗(yàn)證中 : 1:mariadb-libs-5.5.52-1.el7.x86_64 2/2
刪除:
mariadb-libs.x86_64 1:5.5.52-1.el7
作為依賴(lài)被刪除:
postfix.x86_64 2:2.10.1-6.el7
完畢!
2.增加MariaDB的倉(cāng)庫(kù)源
[root@hadoop01 home]#vi /etc/yum.repos.d/MariaDB.repo 增加MariaDB的數(shù)據(jù)庫(kù)鏡像信息
# MariaDB 10.2 CentOS repository list - created 2017-12-26 06:46 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
文件信息請(qǐng)參考[https://downloads.mariadb.org/mariadb/repositories/#mirror=tuna] 設(shè)置具體需要安裝的版本复濒,本文下載MariaDB10.2穩(wěn)定版府喳。
3.安裝MariaDB
[root@localhost ~]# yum -y install MariaDB-server MariaDB-client
已加載插件:fastestmirror, langpacks
mariadb | 2.9 kB 00:00:00
mariadb/primary_db | 21 kB 00:00:01
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.sohu.com
* updates: mirrors.aliyun.com
正在解決依賴(lài)關(guān)系
--> 正在檢查事務(wù)
---> 軟件包 MariaDB-client.x86_64.0.10.2.11-1.el7.centos 將被 安裝
--> 正在處理依賴(lài)關(guān)系 MariaDB-common蒲肋,它被軟件包 MariaDB-client-10.2.11-1.el7.centos.x86_64 需要
---> 軟件包 MariaDB-server.x86_64.0.10.2.11-1.el7.centos 將被 安裝
--> 正在處理依賴(lài)關(guān)系 perl(DBI),它被軟件包 MariaDB-server-10.2.11-1.el7.centos.x86_64 需要
--> 正在處理依賴(lài)關(guān)系 galera,它被軟件包 MariaDB-server-10.2.11-1.el7.centos.x86_64 需要
--> 正在檢查事務(wù)
---> 軟件包 MariaDB-common.x86_64.0.10.2.11-1.el7.centos 將被 安裝
--> 正在處理依賴(lài)關(guān)系 MariaDB-compat兜粘,它被軟件包 MariaDB-common-10.2.11-1.el7.centos.x86_64 需要
---> 軟件包 galera.x86_64.0.25.3.22-1.rhel7.el7.centos 將被 安裝
--> 正在處理依賴(lài)關(guān)系 libboost_program_options.so.1.53.0()(64bit)申窘,它被軟件包 galera-25.3.22-1.rhel7.el7.centos.x86_64 需要
---> 軟件包 perl-DBI.x86_64.0.1.627-4.el7 將被 安裝
--> 正在處理依賴(lài)關(guān)系 perl(RPC::PlServer) >= 0.2001,它被軟件包 perl-DBI-1.627-4.el7.x86_64 需要
--> 正在處理依賴(lài)關(guān)系 perl(RPC::PlClient) >= 0.2000孔轴,它被軟件包 perl-DBI-1.627-4.el7.x86_64 需要
--> 正在檢查事務(wù)
---> 軟件包 MariaDB-compat.x86_64.0.10.2.11-1.el7.centos 將被 安裝
---> 軟件包 boost-program-options.x86_64.0.1.53.0-27.el7 將被 安裝
---> 軟件包 perl-PlRPC.noarch.0.0.2020-14.el7 將被 安裝
--> 正在處理依賴(lài)關(guān)系 perl(Net::Daemon) >= 0.13剃法,它被軟件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在處理依賴(lài)關(guān)系 perl(Net::Daemon::Test),它被軟件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在處理依賴(lài)關(guān)系 perl(Net::Daemon::Log)路鹰,它被軟件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在處理依賴(lài)關(guān)系 perl(Compress::Zlib)贷洲,它被軟件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在檢查事務(wù)
---> 軟件包 perl-IO-Compress.noarch.0.2.061-2.el7 將被 安裝
--> 正在處理依賴(lài)關(guān)系 perl(Compress::Raw::Zlib) >= 2.061,它被軟件包 perl-IO-Compress-2.061-2.el7.noarch 需要
--> 正在處理依賴(lài)關(guān)系 perl(Compress::Raw::Bzip2) >= 2.061晋柱,它被軟件包 perl-IO-Compress-2.061-2.el7.noarch 需要
---> 軟件包 perl-Net-Daemon.noarch.0.0.48-5.el7 將被 安裝
--> 正在檢查事務(wù)
---> 軟件包 perl-Compress-Raw-Bzip2.x86_64.0.2.061-3.el7 將被 安裝
---> 軟件包 perl-Compress-Raw-Zlib.x86_64.1.2.061-4.el7 將被 安裝
--> 解決依賴(lài)關(guān)系完成
依賴(lài)關(guān)系解決
============================================================================================================================================================================================================================================
Package 架構(gòu) 版本 源 大小
============================================================================================================================================================================================================================================
正在安裝:
MariaDB-client x86_64 10.2.11-1.el7.centos mariadb 48 M
MariaDB-server x86_64 10.2.11-1.el7.centos mariadb 110 M
為依賴(lài)而安裝:
MariaDB-common x86_64 10.2.11-1.el7.centos mariadb 154 k
MariaDB-compat x86_64 10.2.11-1.el7.centos mariadb 2.8 M
boost-program-options x86_64 1.53.0-27.el7 base 156 k
galera x86_64 25.3.22-1.rhel7.el7.centos mariadb 8.0 M
perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k
perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k
perl-DBI x86_64 1.627-4.el7 base 802 k
perl-IO-Compress noarch 2.061-2.el7 base 260 k
perl-Net-Daemon noarch 0.48-5.el7 base 51 k
perl-PlRPC noarch 0.2020-14.el7 base 36 k
事務(wù)概要
============================================================================================================================================================================================================================================
等待下載完成,下載完成后會(huì)自動(dòng)安裝优构。
4.MariaDB服務(wù)管理
[root@hadoop01 home]# systemctl start mariadb # 開(kāi)啟數(shù)據(jù)庫(kù)服務(wù)
[root@hadoop01 home]# systemctl enable mariadb # 開(kāi)機(jī)自啟動(dòng)
[root@hadoop01 home]# systemctl restart mariadb # 重啟服務(wù)
[root@hadoop01 home]# systemctl status mariadb #查看數(shù)據(jù)庫(kù)狀態(tài)
[root@hadoop01 home]# systemctl stop mariadb.service # 停止數(shù)據(jù)庫(kù)服務(wù)
5.數(shù)據(jù)庫(kù)登錄
[root@hadoop01 home]# mysql -uroot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.2.11-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)]>
6.設(shè)置數(shù)據(jù)庫(kù)密碼
[root@hadoop01 home]# 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): #輸入當(dāng)前密碼,一般沒(méi)設(shè)置直接回車(chē)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
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 #是否設(shè)置root密碼雁竞,輸入y
New password: #輸入新密碼
Re-enter new password: #重復(fù)密碼
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] #刪除匿名用戶(hù) y
... 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遠(yuǎn)程登錄
... 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數(shù)據(jù)庫(kù)
- 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] #是否重新加載權(quá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!
測(cè)試登錄
[root@hadoop01 home]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 22
Server version: 10.2.11-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)]>
7.配置MariaDB數(shù)據(jù)庫(kù)字符集
[root@hadoop01 home]# cd /etc/my.cnf.d/
[root@hadoop01 my.cnf.d]# ls
enable_encryption.preset mysql-clients.cnf server.cnf
[root@hadoop01 my.cnf.d]# vim server.cnf
(1).在server.cnf 文件在[mysqld]標(biāo)簽下增加以下信息:
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
(2).在mysql-clients.cnf 文件[mysql]標(biāo)簽下增加如下信息:
default-character-set=utf8
全部配置完成后重啟數(shù)據(jù)庫(kù)服務(wù)
[root@hadoop01 my.cnf.d]# systemctl restart mariadb
之后進(jìn)入MariaDB查看字符集
[root@hadoop01 my.cnf.d]# systemctl restart mariadb
[root@hadoop01 my.cnf.d]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.2.11-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)]>
字符集配置完成
8.創(chuàng)建用戶(hù)钦椭、添加授權(quán)
(1).創(chuàng)建用戶(hù)
MariaDB [(none)]> create user hadoop@localhost identified by 'xxxx'; #請(qǐng)?zhí)鎿Qxx為密碼
Query OK, 0 rows affected (0.01 sec)
(2).為用戶(hù)進(jìn)行操作授權(quán)
MariaDB [(none)]> grant all on *.* to hadoop@locahost identified by 'xxxx'; #請(qǐng)?zhí)鎿Qxx為密碼
Query OK, 0 rows affected (0.00 sec)
(3).授權(quán)外網(wǎng)登錄權(quán)限
MariaDB [(none)]> grant all privileges on *.* to hadoop@'%' identified by 'xxx'; #請(qǐng)?zhí)鎿Qxx為密碼
Query OK, 0 rows affected (0.00 sec)
查詢(xún)用戶(hù)授權(quán)結(jié)果
MariaDB [mysql]> select host,user,password from user;
+-----------+--------+-------------------------------------------+
| host | user | password |
+-----------+--------+-------------------------------------------+
| localhost | root | *7D8990305DAAE2A688433D400E6559EBDF439529 |
| 127.0.0.1 | root | *7D8990305DAAE2A688433D400E6559EBDF439529 |
| ::1 | root | *7D8990305DAAE2A688433D400E6559EBDF439529 |
| locahost | hadoop | *7D8990305DAAE2A688433D400E6559EBDF439529 |
| localhost | hadoop | *AB7E9F716159ED905A3E5DA78DA0DFD516C429E1 |
| % | hadoop | *7D8990305DAAE2A688433D400E6559EBDF439529 |
+-----------+--------+-------------------------------------------+
6 rows in set (0.00 sec)