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-*全部删除:

  1. [root@localhost ~]# rpm -qa | grep mariadb
  2. mariadb-server-5.5.52-1.el7.x86_64
  3. mariadb-libs-5.5.52-1.el7.x86_64
  4. [root@localhost ~]# rpm -e mysql-*
  5. 错误:未安装软件包 mysql-*

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

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

  1. [root@localhost ~]# yum remove mysql mysql-server mysql-libs compat-mysql51
  2. 已加载插件:fastestmirror, langpacks
  3. 参数 mysql 没有匹配
  4. 参数 mysql-server 没有匹配
  5. 参数 compat-mysql51 没有匹配
  6. 正在解决依赖关系
  7. --> 正在检查事务
  8. ---> 软件包 mariadb-libs.x86_64.1.5.5.52-1.el7 将被 删除
  9. --> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 perl-DBD-MySQL-4.023-5.el7.x86_64 需要
  10. --> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-6.el7.x86_64 需要
  11. --> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 1:qt-mysql-4.8.5-13.el7.x86_64 需要..........
  1. 删除:
  2. mariadb-libs.x86_64 1:5.5.52-1.el7
  3.  
  4. 作为依赖被删除:
  5. akonadi-mysql.x86_64 0:1.9.2-4.el7 mariadb-server.x86_64 1:5.5.52-1.el7
  6. perl-DBD-MySQL.x86_64 0:4.023-5.el7 postfix.x86_64 2:2.10.1-6.el7
  7. qt-mysql.x86_64 1:4.8.5-13.el7
  8.  
  9. 完毕!
  10. [root@localhost ~]# rpm -qa|grep mariadb
  11. [root@localhost ~]#

3.开始新的安装, 创建MariaDB.repo文件

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

插入以下内容:

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

系统及版本选择:https://downloads.mariadb.org/mariadb/repositories/#mirror=tuna

4.运行安装命令安装MariaDB

  1. [root@localhost ~]# yum -y install MariaDB-server MariaDB-client
  2. 已加载插件:fastestmirror, langpacks
  3. mariadb | 2.9 kB 00:00
  4. mariadb/primary_db | 18 kB 00:09
  5. Determining fastest mirrors
  6. * base: mirrors.btte.net
  7. * extras: mirrors.zju.edu.cn
  8. * updates: mirrors.zju.edu.cn
  9. 正在解决依赖关系
  10. --> 正在检查事务
  11. ---> 软件包 MariaDB-client.x86_64.0.10.2.4-1.el7.centos 将被 安装
  12. --> 正在处理依赖关系 MariaDB-common,它被软件包 MariaDB-client-10.2.4-1.el7.centos.x86_64 需要
  13. ---> 软件包 MariaDB-server.x86_64.0.10.2.4-1.el7.centos 将被 安装
  14. --> 正在处理依赖关系 galera,它被软件包 MariaDB-server-10.2.4-1.el7.centos.x86_64 需要
  15. --> 正在处理依赖关系 libjemalloc.so.1()(64bit),它被软件包 MariaDB-server-10.2.4-1.el7.centos.x86_64 需要
  16. --> 正在检查事务
  17. ---> 软件包 MariaDB-common.x86_64.0.10.2.4-1.el7.centos 将被 安装
  18. --> 正在处理依赖关系 MariaDB-compat,它被软件包 MariaDB-common-10.2.4-1.el7.centos.x86_64 需要
  19. ---> 软件包 galera.x86_64.0.25.3.19-1.rhel7.el7.centos 将被 安装
  20. ---> 软件包 jemalloc.x86_64.0.3.6.0-1.el7 将被 安装
  21. --> 正在检查事务
  22. ---> 软件包 MariaDB-compat.x86_64.0.10.2.4-1.el7.centos 将被 安装
  23. --> 解决依赖关系完成
  24.  
  25. 依赖关系解决
  26.  
  27. ================================================================================
  28. Package 架构 版本 大小
  29. ================================================================================
  30. 正在安装:
  31. MariaDB-client x86_64 10.2.4-1.el7.centos mariadb 48 M
  32. MariaDB-server x86_64 10.2.4-1.el7.centos mariadb 113 M
  33. 为依赖而安装:
  34. MariaDB-common x86_64 10.2.4-1.el7.centos mariadb 104 k
  35. MariaDB-compat x86_64 10.2.4-1.el7.centos mariadb 2.8 M
  36. galera x86_64 25.3.19-1.rhel7.el7.centos mariadb 8.0 M
  37. jemalloc x86_64 3.6.0-1.el7 mariadb 104 k
  38.  
  39. 事务概要
  40. ================================================================================
  41. 安装 2 软件包 (+4 依赖软件包)
  42. ....

首先下载安装包,然后进行自动安装,安装成功之后启动MariaDB服务。

  1. systemctl start mariadb #启动服务
  2. systemctl enable mariadb #设置开机启动
  3. systemctl restart mariadb #重新启动
  4. systemctl stop mariadb.service #停止MariaDB

5.登录到数据库

  用mysql -uroot命令登录到MariaDB,此时root账户的密码为空。

6.进行MariaDB的相关简单配置,使用mysql_secure_installation命令进行配置。

  1. 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完成,接下来测试登录

  1. mysql -uroot -ppassword

完成。

7.配置MariaDB的字符集

  查看/etc/my.cnf文件内容,其中包含一句!includedir /etc/my.cnf.d 说明在该配置文件中引入/etc/my.cnf.d 目录下的配置文件。

1)使用vi server.cnf命令编辑server.cnf文件,在[mysqld]标签下添加

  1. init_connect='SET collation_connection = utf8_unicode_ci'
  2. init_connect='SET NAMES utf8'
  3. character-set-server=utf8
  4. collation-server=utf8_unicode_ci
  5. skip-character-set-client-handshake

  如果/etc/my.cnf.d 目录下无server.cnf文件,则直接在/etc/my.cnf文件的[mysqld]标签下添加以上内容。

2)文件/etc/my.cnf.d/client.cnf

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

在[client]中添加

  1. default-character-set=utf8

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

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

在[mysql]中添加

  1. default-character-set=utf8

全部配置完成,重启mariadb

  1. systemctl restart mariadb

之后进入MariaDB查看字符集

  1. mysql> show variables like "%character%";show variables like "%collation%";

显示为

  1. +--------------------------+----------------------------+
  2. | Variable_name | Value |
  3. +--------------------------+----------------------------+
  4. | character_set_client | utf8 |
  5. | character_set_connection | utf8 |
  6. | character_set_database | utf8 |
  7. | character_set_filesystem | binary |
  8. | character_set_results | utf8 |
  9. | character_set_server | utf8 |
  10. | character_set_system | utf8 |
  11. | character_sets_dir | /usr/share/mysql/charsets/ |
  12. +--------------------------+----------------------------+
  13. 8 rows in set (0.00 sec)
  14.  
  15. +----------------------+-----------------+
  16. | Variable_name | Value |
  17. +----------------------+-----------------+
  18. | collation_connection | utf8_unicode_ci |
  19. | collation_database | utf8_unicode_ci |
  20. | collation_server | utf8_unicode_ci |
  21. +----------------------+-----------------+
  22. 3 rows in set (0.00 sec)

字符集配置完成。

8. 添加用户,设置权限

创建用户命令

  1. mysql>create user username@localhost identified by 'password';

直接创建用户并授权的命令

  1. mysql>grant all on *.* to username@localhost indentified by 'password';

授予外网登陆权限

  1. mysql>grant all privileges on *.* to username@'%' identified by 'password';

授予权限并且可以授权

  1. mysql>grant all privileges on *.* to username@'hostname' identified by 'password' with grant option;
  1. MariaDB [mysql]> select host,user,password from user;
  2. +-----------------------+-------+------------------------+
  3. | host | user | password |
  4. +-----------------------+-------+------------------------+
  5. | localhost | root | *E87F9354F7E889A65E... |
  6. | localhost.localdomain | root | *E87F9354F7E889A65E... |
  7. | 127.0.0.1 | root | *E87F9354F7E889A65E... |
  8. | ::1 | root | *E87F9354F7E889A65E... |
  9. | localhost | | |
  10. | localhost.localdomain | | |
  11. +-----------------------+-------+------------------------+
  12. 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

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

ECS——CentOS7下使用yum安装MariaDB的更多相关文章

  1. CentOS7下使用yum安装MariaDB

    从CentOS 7开始,使用 MariaDB 替代默认的 MySQL.MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MyS ...

  2. centos7下使用yum安装mysql

    CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1. 下载mysql的repo源 wget http://repo.mysql.com/m ...

  3. centos7下使用yum安装pip

    centos7下使用yum安装pip 首先安装epel扩展源: yum -y install epel-release 更新完成之后,就可安装pip: yum -y install python-pi ...

  4. centos7下使用yum安装redis

    centos7下使用yum安装Redis 第一步:安装 yum –y install redis 第二步:启动 systemctl start redis.service 第三步:设置开机启动 sys ...

  5. CentOS7下使用YUM安装mariadb10

    1:由于centos7 默认使用yum安装MySQL的话就会安装mariadb,只是安装的版本停留在mariadb5.x,版本比较低.如果我们需要安装mariadb10这里就需要删除mariadb-l ...

  6. Centos6下使用yum安装MariaDB

    1)增加mariaDB的yum源 1 2 3 4 5 6 7 8 9 [root@centos6-test08 ~]# cd /etc/yum.repos.d/ [root@centos6-test0 ...

  7. 日常工作问题解决:centos7下使用yum安装软件报yum.pid锁定

    问题描述: 在centos7下使用yum进行软件安装时报yum.pid已经被锁定,如下所示: [root@centos7-129 ~]# yum -y install dhcp 已加载插件:faste ...

  8. Linux下使用yum安装MariaDB

    版本:centos7 Linux下安装MariaDB官方文档参见:https://mariadb.com/kb/zh-cn/installing-mariadb-with-yum/ 1.创建Maria ...

  9. CentOS7 下使用YUM安装 MySQL5.7

    于2015年10月19日(美国时间),Oracle公司发布了开源数据库MySQL的最新版本5.7.到现在已有将近3年之久,经过这几年的改进,MySQL5.7性能最高可达前一个版本的3倍,现在官网的最新 ...

随机推荐

  1. client模式下对应接口加入桥接出错

    client模式下,响应的接口wlan0 加入桥接时出现如下错误: root@root:~# brctl addif br-lan wlan0brctl: bridge br-lan: Operati ...

  2. css之absolute

    一.absolute和float有相同的特性,包裹性和破坏性 1.absolute和float的相似(看下面的demo,如果图片在左上角,那么用float和absolute都一样) <!doct ...

  3. Math对象应用详解

    JavaScript中的Math对象提供了大量的算术运算功能和数值操作方法. JavaScript中的Math对象的与众不同之处在于,它是一个全局对象.在使用Math对象之前,既不需要将一个变量声明为 ...

  4. CPU密集型 VS IO密集型

    CPU密集型 CPU密集型也叫计算密集型,指的是系统的硬盘.内存性能相对CPU要好很多,此时,系统运作大部分的状况是CPU Loading 100%,CPU要读/写I/O(硬盘/内存),I/O在很短的 ...

  5. linux 下 eclipse 安装

    下载: 官网选择相应安装包下载,我这里下了tar.gz包 安装: tar xzvf eclipse-inst-linux64.tar.gz 设置环境变量 export JAVA_HOME=/usr/l ...

  6. samba 设置文件的读写权限

    原文:https://blog.csdn.net/lan120576664/article/details/50396511 打开配置文件 sudo pico /etc/samba/smb.conf ...

  7. 线段树解LIS

    先是nlogn的LIS解法 /* LIS nlogn解法 */ #include<iostream> #include<cstring> #include<cstdio& ...

  8. python 全栈开发,Day111(客户管理之 编辑权限(二),Django表单集合Formset,ORM之limit_choices_to,构造家族结构)

    昨日内容回顾 1. 权限系统的流程? 2. 权限的表有几个? 3. 技术点 中间件 session orm - 去重 - 去空 inclusion_tag filter 有序字典 settings配置 ...

  9. LeetCode | Reverse Words in a String(C#)

    题目: Given an input string, reverse the string word by word. For example,Given s = "the sky is b ...

  10. MockMvc 对 Spring Boot 进行单元测试

    import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.ann ...