Centos7.2安裝MariaDB

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)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市碑诉,隨后出現(xiàn)的幾起案子彪腔,更是在濱河造成了極大的恐慌,老刑警劉巖进栽,帶你破解...
    沈念sama閱讀 212,222評(píng)論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件德挣,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡泪幌,警方通過(guò)查閱死者的電腦和手機(jī)盲厌,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,455評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)祸泪,“玉大人吗浩,你說(shuō)我怎么就攤上這事∶话” “怎么了懂扼?”我有些...
    開(kāi)封第一講書(shū)人閱讀 157,720評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)右蒲。 經(jīng)常有香客問(wèn)我阀湿,道長(zhǎng),這世上最難降的妖魔是什么瑰妄? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,568評(píng)論 1 284
  • 正文 為了忘掉前任陷嘴,我火速辦了婚禮,結(jié)果婚禮上间坐,老公的妹妹穿的比我還像新娘灾挨。我一直安慰自己邑退,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,696評(píng)論 6 386
  • 文/花漫 我一把揭開(kāi)白布劳澄。 她就那樣靜靜地躺著地技,像睡著了一般。 火紅的嫁衣襯著肌膚如雪秒拔。 梳的紋絲不亂的頭發(fā)上莫矗,一...
    開(kāi)封第一講書(shū)人閱讀 49,879評(píng)論 1 290
  • 那天,我揣著相機(jī)與錄音砂缩,去河邊找鬼作谚。 笑死,一個(gè)胖子當(dāng)著我的面吹牛庵芭,可吹牛的內(nèi)容都是我干的食磕。 我是一名探鬼主播,決...
    沈念sama閱讀 39,028評(píng)論 3 409
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼喳挑,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了滔悉?” 一聲冷哼從身側(cè)響起伊诵,我...
    開(kāi)封第一講書(shū)人閱讀 37,773評(píng)論 0 268
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎回官,沒(méi)想到半個(gè)月后曹宴,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,220評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡歉提,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,550評(píng)論 2 327
  • 正文 我和宋清朗相戀三年笛坦,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片苔巨。...
    茶點(diǎn)故事閱讀 38,697評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡版扩,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出侄泽,到底是詐尸還是另有隱情礁芦,我是刑警寧澤,帶...
    沈念sama閱讀 34,360評(píng)論 4 332
  • 正文 年R本政府宣布悼尾,位于F島的核電站柿扣,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏闺魏。R本人自食惡果不足惜未状,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,002評(píng)論 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望析桥。 院中可真熱鬧司草,春花似錦艰垂、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,782評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至吨岭,卻和暖如春拉宗,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背辣辫。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,010評(píng)論 1 266
  • 我被黑心中介騙來(lái)泰國(guó)打工旦事, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人急灭。 一個(gè)月前我還...
    沈念sama閱讀 46,433評(píng)論 2 360
  • 正文 我出身青樓姐浮,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親葬馋。 傳聞我的和親對(duì)象是個(gè)殘疾皇子卖鲤,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,587評(píng)論 2 350

推薦閱讀更多精彩內(nèi)容