Centos7.2安装MariaDB

1.检查是否已经具有MariaDB相关安装,并删除已有安装

[root@hadoop01 home]# rpm -qa|grep mariadb  #查询已安装包
mariadb-libs-5.5.52-1.el7.x86_64
[root@hadoop01 home]# rpm -e --nodeps mariadb-*   # 移除已安装包
错误:未安装软件包 mariadb-* 
[root@hadoop01 home]# yum remove mysql mysql-server mysql-libs compat-mysql51   # 删除Mysql服务
已加载插件:fastestmirror, langpacks
参数 mysql 没有匹配
参数 mysql-server 没有匹配
参数 compat-mysql51 没有匹配
正在解决依赖关系
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.52-1.el7 将被 删除
--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-6.el7.x86_64 需要
--> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-6.el7.x86_64 需要
--> 正在检查事务
---> 软件包 postfix.x86_64.2.2.10.1-6.el7 将被 删除
  > 解决依赖关系完成
▽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     

依赖关系解决

============================================================================================================================================================================================================================================
 Package                                                    架构                                                 版本                                                         源                                                       大小
============================================================================================================================================================================================================================================
正在删除:
 mariadb-libs                                               x86_64                                               1:5.5.52-1.el7                                               @anaconda                                               4.4 M
为依赖而移除:
 postfix                                                    x86_64                                               2:2.10.1-6.el7                                               @anaconda                                                12 M

事务概要
============================================================================================================================================================================================================================================
移除  1 软件包 (+1 依赖软件包)

安装大小:17 M
是否继续?[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 
  验证中      : 2:postfix-2.10.1-6.el7.x86_64                                                                                                                                                                                           1/2 
  验证中      : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                                                                                                                                      2/2 

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

作为依赖被删除:
  postfix.x86_64 2:2.10.1-6.el7                                                                                                                                                                                                             

完毕!

2.增加MariaDB的仓库源

[root@hadoop01 home]#vi /etc/yum.repos.d/MariaDB.repo   增加MariaDB的数据库镜像信息
# 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

文件信息请参考[https://downloads.mariadb.org/mariadb/repositories/#mirror=tuna] 设置具体需要安装的版本,本文下载MariaDB10.2稳定版。

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
正在解决依赖关系
--> 正在检查事务
---> 软件包 MariaDB-client.x86_64.0.10.2.11-1.el7.centos 将被 安装
--> 正在处理依赖关系 MariaDB-common,它被软件包 MariaDB-client-10.2.11-1.el7.centos.x86_64 需要
---> 软件包 MariaDB-server.x86_64.0.10.2.11-1.el7.centos 将被 安装
--> 正在处理依赖关系 perl(DBI),它被软件包 MariaDB-server-10.2.11-1.el7.centos.x86_64 需要
--> 正在处理依赖关系 galera,它被软件包 MariaDB-server-10.2.11-1.el7.centos.x86_64 需要
--> 正在检查事务
---> 软件包 MariaDB-common.x86_64.0.10.2.11-1.el7.centos 将被 安装
--> 正在处理依赖关系 MariaDB-compat,它被软件包 MariaDB-common-10.2.11-1.el7.centos.x86_64 需要
---> 软件包 galera.x86_64.0.25.3.22-1.rhel7.el7.centos 将被 安装
--> 正在处理依赖关系 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 将被 安装
--> 正在处理依赖关系 perl(RPC::PlServer) >= 0.2001,它被软件包 perl-DBI-1.627-4.el7.x86_64 需要
--> 正在处理依赖关系 perl(RPC::PlClient) >= 0.2000,它被软件包 perl-DBI-1.627-4.el7.x86_64 需要
--> 正在检查事务
---> 软件包 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 将被 安装
--> 正在处理依赖关系 perl(Net::Daemon) >= 0.13,它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在处理依赖关系 perl(Net::Daemon::Test),它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在处理依赖关系 perl(Net::Daemon::Log),它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在处理依赖关系 perl(Compress::Zlib),它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在检查事务
---> 软件包 perl-IO-Compress.noarch.0.2.061-2.el7 将被 安装
--> 正在处理依赖关系 perl(Compress::Raw::Zlib) >= 2.061,它被软件包 perl-IO-Compress-2.061-2.el7.noarch 需要
--> 正在处理依赖关系 perl(Compress::Raw::Bzip2) >= 2.061,它被软件包 perl-IO-Compress-2.061-2.el7.noarch 需要
---> 软件包 perl-Net-Daemon.noarch.0.0.48-5.el7 将被 安装
--> 正在检查事务
---> 软件包 perl-Compress-Raw-Bzip2.x86_64.0.2.061-3.el7 将被 安装
---> 软件包 perl-Compress-Raw-Zlib.x86_64.1.2.061-4.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

============================================================================================================================================================================================================================================
 Package                                                         架构                                           版本                                                                  源                                               大小
============================================================================================================================================================================================================================================
正在安装:
 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
为依赖而安装:
 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

事务概要
============================================================================================================================================================================================================================================

等待下载完成,下载完成后会自动安装。

4.MariaDB服务管理

[root@hadoop01 home]# systemctl start mariadb               # 开启数据库服务
[root@hadoop01 home]# systemctl enable mariadb              # 开机自启动
[root@hadoop01 home]# systemctl restart mariadb             # 重启服务      
[root@hadoop01 home]# systemctl status mariadb              #查看数据库状态
[root@hadoop01 home]# systemctl stop mariadb.service        # 停止数据库服务

5.数据库登录

[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.设置数据库密码

[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):    #输入当前密码,一般没设置直接回车
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           #是否设置root密码,输入y
New password:                            #输入新密码
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]            #删除匿名用户  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远程登录
 ... 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@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数据库字符集

[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]标签下增加以下信息:

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]标签下增加如下信息:

default-character-set=utf8

全部配置完成后重启数据库服务

[root@hadoop01 my.cnf.d]# systemctl restart mariadb

之后进入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.创建用户、添加授权

(1).创建用户

MariaDB [(none)]> create user  hadoop@localhost identified by 'xxxx';  #请替换xx为密码
Query OK, 0 rows affected (0.01 sec)

(2).为用户进行操作授权

MariaDB [(none)]> grant all on *.* to hadoop@locahost identified by 'xxxx';  #请替换xx为密码
Query OK, 0 rows affected (0.00 sec)

(3).授权外网登录权限

MariaDB [(none)]> grant all privileges on *.* to hadoop@'%' identified by 'xxx'; #请替换xx为密码
Query OK, 0 rows affected (0.00 sec)

查询用户授权结果

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)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,406评论 6 503
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,732评论 3 393
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,711评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,380评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,432评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,301评论 1 301
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,145评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,008评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,443评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,649评论 3 334
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,795评论 1 347
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,501评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,119评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,731评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,865评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,899评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,724评论 2 354

推荐阅读更多精彩内容