CentOS7下使用yum安装MariaDB

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

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

mariadb-server-5.5.52-1.el7.x86_64

mariadb-libs-5.5.52-1.el7.x86_64

[root@localhost ~]# rpm -e mysql-*

错误:未安装软件包 mysql-*

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

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

[root@localhost ~]# yum remove mysql mysql-server mysql-libs compat-mysql51

已加载插件:fastestmirror, langpacks

参数 mysql 没有匹配

参数 mysql-server 没有匹配

参数 compat-mysql51 没有匹配

正在解决依赖关系--> 正在检查事务---> 软件包 mariadb-libs.x86_64.1.5.5.52-1.el7 将被 删除--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 perl-DBD-MySQL-4.023-5.el7.x86_64 需要--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-6.el7.x86_64 需要--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 1:qt-mysql-4.8.5-13.el7.x86_64 需要..........

删除:

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

作为依赖被删除:

akonadi-mysql.x86_64 0:1.9.2-4.el7     mariadb-server.x86_64 1:5.5.52-1.el7

perl-DBD-MySQL.x86_64 0:4.023-5.el7    postfix.x86_64 2:2.10.1-6.el7

qt-mysql.x86_64 1:4.8.5-13.el7

完毕!

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

[root@localhost ~]#

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

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

插入以下内容:

# MariaDB 10.2.4 CentOS repository list - created 2017-05-05 16:13 UTC

# http://downloads.mariadb.org/mariadb/repositories/

[mariadb]

name = MariaDB

baseurl = http://yum.mariadb.org/10.2.4/centos7-amd64

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1

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

4.运行安装命令安装MariaDB

[root@localhost ~]# yum -y install MariaDB-server MariaDB-client

已加载插件:fastestmirror, langpacks

mariadb                                                  | 2.9 kB     00:00

mariadb/primary_db                                         |  18 kB   00:09

Determining fastest mirrors

* base: mirrors.btte.net

* extras: mirrors.zju.edu.cn

* updates: mirrors.zju.edu.cn

正在解决依赖关系--> 正在检查事务---> 软件包 MariaDB-client.x86_64.0.10.2.4-1.el7.centos 将被 安装--> 正在处理依赖关系 MariaDB-common,它被软件包 MariaDB-client-10.2.4-1.el7.centos.x86_64 需要---> 软件包 MariaDB-server.x86_64.0.10.2.4-1.el7.centos 将被 安装--> 正在处理依赖关系 galera,它被软件包 MariaDB-server-10.2.4-1.el7.centos.x86_64 需要--> 正在处理依赖关系 libjemalloc.so.1()(64bit),它被软件包 MariaDB-server-10.2.4-1.el7.centos.x86_64 需要--> 正在检查事务---> 软件包 MariaDB-common.x86_64.0.10.2.4-1.el7.centos 将被 安装--> 正在处理依赖关系 MariaDB-compat,它被软件包 MariaDB-common-10.2.4-1.el7.centos.x86_64 需要---> 软件包 galera.x86_64.0.25.3.19-1.rhel7.el7.centos 将被 安装---> 软件包 jemalloc.x86_64.0.3.6.0-1.el7 将被 安装--> 正在检查事务---> 软件包 MariaDB-compat.x86_64.0.10.2.4-1.el7.centos 将被 安装--> 解决依赖关系完成

依赖关系解决

================================================================================

Package            架构       版本                           源           大小================================================================================

正在安装:

MariaDB-client     x86_64     10.2.4-1.el7.centos            mariadb      48 M

MariaDB-server     x86_64     10.2.4-1.el7.centos            mariadb     113 M

为依赖而安装:

MariaDB-common     x86_64     10.2.4-1.el7.centos            mariadb     104 k

MariaDB-compat     x86_64     10.2.4-1.el7.centos            mariadb     2.8 M

galera             x86_64     25.3.19-1.rhel7.el7.centos     mariadb     8.0 M

jemalloc           x86_64     3.6.0-1.el7                    mariadb     104 k

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

安装  2 软件包 (+4 依赖软件包)

....

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

systemctl start mariadb #启动服务

systemctl enable mariadb #设置开机启动

systemctl restart mariadb #重新启动

systemctl stop mariadb.service #停止MariaDB

5.登录到数据库

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

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

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

mysql -uroot -ppassword

完成。

7.配置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

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

在[client]中添加

default-character-set=utf8

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

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

在[mysql]中添加

default-character-set=utf8

全部配置完成,重启mariadb

systemctl restart mariadb

之后进入MariaDB查看字符集

mysql> 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)

字符集配置完成。

8. 添加用户,设置权限

创建用户命令

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

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

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

授予外网登陆权限

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

授予权限并且可以授权

mysql>grant all privileges on *.* to username@'hostname' identified by 'password' with grant option;

MariaDB [mysql]> select host,user,password from user;+-----------------------+-------+------------------------+

| host                  | user  | password               |

+-----------------------+-------+------------------------+

| localhost             | root  | *E87F9354F7E889A65E... |

| localhost.localdomain | root  | *E87F9354F7E889A65E... |

| 127.0.0.1             | root  | *E87F9354F7E889A65E... |

| ::1                   | root  | *E87F9354F7E889A65E... |

| localhost             |       |                        |

| localhost.localdomain |       |                        |

+-----------------------+-------+------------------------+

7 rows in set (0.00 sec)

查询各Schema和Table占用的空间:

MariaDB [information_schema]> use information_schema;

MariaDB [information_schema]> select table_schema,round(sum(DATA_LENGTH/1024/1024),2) as datasize  from tables group by table_schema;+--------------------+----------+

| table_schema       | datasize |

+--------------------+----------+

| common             |     0.05 |

| information_schema |     0.09 |

| mysql              |     9.11 |

| nemo               |   103.23 |

| river              |     3.78 |

+--------------------+----------+

5 rows in set (2.026 sec)

MariaDB [information_schema]> select table_name,concat(round(sum(data_length/1024/1024),2),'MB') as datasize from tables where table_schema='nemo' group by table_name;
+---------------------------------+----------+ 
| table_name | datasize | 
+---------------------------------+----------+
| actions             | 0.05MB | 
| addresses            | 0.02MB | 
| addressfieldattributes    | 0.02MB | 
| addressprops          | 0.02MB |
| composedtypes          | 1.52MB |
| composedtypeslp        | 1.52MB |
| comptypegrp2comptype      | 0.05MB |
| config             | 0.02MB |
| itemcockpittemplrels      | 0.02MB |
| itemsynctimestamps        | 2.52MB |
| keyfeature            | 0.02MB |
| keyfeaturelp           | 0.02MB |
| keyvaluemap           | 2.52MB |
| keywords             | 0.02MB |
| keywordsuggestionrule     | 0.02MB |
+---------------------------------+----------+
15 rows in set (0.544 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

忘记root用户名和密码

首先用 killall -TERM mysqld  向mysqld server 发送kill命令关掉mysqld server(不是 kill -9),你必须是UNIX的root用户或者是你所运行的SERVER上的同等用户,才能执行这个操作

然后  /usr/bin/mysqld_safe  --skip-grant-tables --skip-networking &

登录 : mysql -p或者使用mysql无密码登录

>use mysql 
>update user set password=password("new_pass") where user="root";

>flush privileges;

exit;

修改完成之后重启数据库,即可用修改好 root 密码登录 .

centos安装配置mariadb的更多相关文章

  1. 阿里云服务器Linux CentOS安装配置(零)目录

    阿里云服务器Linux CentOS安装配置(零)目录 阿里云服务器Linux CentOS安装配置(一)购买阿里云服务器 阿里云服务器Linux CentOS安装配置(二)yum安装svn 阿里云服 ...

  2. 阿里云服务器Linux CentOS安装配置(九)shell编译、打包、部署

    阿里云服务器Linux CentOS安装配置(九)shell编译.打包.部署 1.查询当前目录以及子目录下所有的java文件,并显示查询结果 find . -name *.java -type f - ...

  3. 阿里云服务器Linux CentOS安装配置(八)nginx安装、配置、域名绑定

    阿里云服务器Linux CentOS安装配置(八)nginx安装.配置.域名绑定 1.安装nginx yum -y install nginx 2.启动nginx service nginx star ...

  4. 阿里云服务器Linux CentOS安装配置(七)域名解析

    阿里云服务器Linux CentOS安装配置(七)域名解析 1.购买域名 登录阿里云,左侧菜单点击[域名],然后[域名注册],完成域名购买.(一般首年45元) 2.添加域名解析 在域名列表里点击你的域 ...

  5. 阿里云服务器Linux CentOS安装配置(六)resin多端口配置、安装、部署

    阿里云服务器Linux CentOS安装配置(六)resin多端口配置.安装.部署 1.下载resin包 http://125.39.66.162/files/2183000003E08525/cau ...

  6. 阿里云服务器Linux CentOS安装配置(五)jetty配置、部署

    阿里云服务器Linux CentOS安装配置(五)jetty配置.部署 1.官网下载jetty:wget http://repo1.maven.org/maven2/org/eclipse/jetty ...

  7. 阿里云服务器Linux CentOS安装配置(四)yum安装tomcat

    阿里云服务器Linux CentOS安装配置(四)yum安装tomcat 1.yum -y install tomcat  执行命令后,会帮你把jdk也安装好 2.tomcat安装目录:/var/li ...

  8. 阿里云服务器Linux CentOS安装配置(三)yum安装mysql

    阿里云服务器Linux CentOS安装配置(三)yum安装mysql 1.执行yum安装mysql命令:yum -y install mysql-server mysql-devel 2.启动mys ...

  9. 阿里云服务器Linux CentOS安装配置(二)yum安装svn

    阿里云服务器Linux CentOS安装配置(二)yum安装svn 1.secureCRT连接服务器 2.先创建一个文件夹,用来按自己的习惯来,用来存放数据 mkdir /data 3.yum安装sv ...

随机推荐

  1. TreeView 三种状态 没多大变化 只是增加了很多函数以方便调用

    using System.Drawing; using System.Windows.Forms; using System.ComponentModel; namespace SimpleCusto ...

  2. SpringCloud(五)之Spring Cloud 中 Feign结合Hystrix断路器开发实战

    1.先讲hystrx(断路器) 在springcloub 中的使用 1.1  加入依赖 注意:网上新旧版本问题,所以要以官网为主,不然部分注解会丢失最新版本 2.0 <dependency> ...

  3. springboot 获取控制器参数的几种方式

    这里介绍springboot 获取控制器参数有四种方式 1.无注解下获取参数 2.使用@RequestParam获取参数 3.传递数组 4.通过URL传递参数 无注解下获取参数无注解下获取参数,需要控 ...

  4. UmUtils得到友盟的渠道号

    import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm ...

  5. jquery简单入门1

    前端 html:展示 form: 属性: action和method 子标签: input(10种) text password radio checkbox file submit button r ...

  6. 连接服务器VNC

    1,启动vnc vncserver 2,提示输入密码 3,Would you like to enter a view-only password (y/n)?  选择n 4,会生成一个端口号 5, ...

  7. ProbCog[github]使用心得

    1. After installing ProbCog,you can run blnquery and mlnquery. If the terminal warns that 'command n ...

  8. web系统认证与鉴权中的一些问题

    认证鉴权系统的初心: 空间管理: 1.他是谁? 他登陆了没有? 2.他要做什么? 2.1 他要使用什么功能? 他是否有这个功能的权限. 2.2 他要使用这个功能做什么操作? 他是否有这个功能的这个操作 ...

  9. *【Python】【demo实验31】【练习实例】【使用turtle画小猪佩奇】

    如下图小猪佩奇: 要求使用turtle画小猪佩奇: 源码: # encoding=utf-8 # -*- coding: UTF-8 -*- # 使用turtle画小猪佩奇 from turtle i ...

  10. sql server存储引擎启动错误(SQL Server could not spawn FRunCM thread)

    错误信息: 中文版: 服务器无法在 'any' <ipv4> 1433 上侦听.错误: 0x277a.若要继续,请通知您的系统管理员. TDSSNIClient 初始化失败,出现错误 0x ...