1 安装并启动 MariaDB

MariaDB 采用 Percona 的 XtraDB 存储引擎替代 MySQL 的 InnoDB,XtraDB 完全兼容 InnoDB。

1.1 安装

MySQL 与 MariaDB 版本对比:

MySQL 版本 MariaDB 版本 主要特点
5.5 5.5
5.6 10
5.7 10.1 通过 gtid 彻底解决主从同步的延迟问题
- 10.2
- 10.3

下载页面,可以查看每个版本的特点。

通过 Yum 安装

对于 CentOS7,通过 yum 安装的版本是 5.5,比较老了:

yum -y install mariadb-server

通过官网安装最新版本

MariaDB 的官方 yum 源在 这里,可用将下面示例中的版本换成适合你的操作系统的最新版本。例如我用的版本是 http://yum.mariadb.org/10.3/centos7-amd64/

首先,配置 yum 源:

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

在里面加入如下内容:

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

然后,开始安装:

yum -y install mariadb-server

1.2 常用命令

在使用 MariaDB 时,命令中可以直接用 mysql 替换 mariadb,例如 systemctl start mariadb 等价于 systemctl start mysql

  • 启动 MariaDB:
systemctl start mariadb
  • 查看服务状态:
systemctl status mariadb

如果 MariaDB 启动成功,状态中会包括“Active: active (running)”,最后一句话一般是:

Apr 17 14:32:54 VM_157_18_centos systemd[1]: Started MariaDB database server.
  • 设置每次服务器重启时都自动启动数据库:
systemctl enable mariadb

上面命令的输出跟下面一样时,表示成功执行:

Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

1.3 其他可用命令

mysql                       mysqld_safe_helper          mysql_secure_installation
mysqlaccess mysqldump mysql_setpermission
mysqladmin mysqldumpslow mysqlshow
mysqlbinlog mysql_find_rows mysqlslap
mysqlbug mysql_fix_extensions mysqltest
mysqlcheck mysqlhotcopy mysql_tzinfo_to_sql
mysql_convert_table_format mysqlimport mysql_upgrade
mysqld_multi mysql_install_db mysql_waitpid
mysqld_safe mysql_plugin mysql_zap

2. 对 MariaDB 服务器进行安全设置

MariaDB 包含一个安全脚本,可以改变一些不安全的默认行为,比如远程登录、简单用户设置等。运行安全脚本:

sudo mysql_secure_installation

脚本的每一步都会有详细的解释。第一个交互部分需要你提供 root 密码,因为刚安装的 MariaDB 还没有设置密码,这里直接按 ENTER 进入下一步。下一步设置 root 用户密码。后面的可以全部输入 Y 使用 MariaDB 的建议操作。完整命令如下

# 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):
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
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] y
... 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] y
- 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] y
... 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!

3. 测试

mysqladmin 执行命令,查看数据库版本:

mysqladmin -u root -p version

输出类似下面:

mysqladmin  Ver 9.0 Distrib 5.5.56-MariaDB, for Linux on x86_64
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Server version 5.5.56-MariaDB
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 14 min 59 sec Threads: 1 Questions: 25 Slow queries: 0 Opens: 1 Flush tables: 2 Open tables: 27 Queries per second avg: 0.027

登录数据库

以 root 身份登录后,可以执行任何操作:

mysql -u root -p

CentOS7 - 安装 MariaDB的更多相关文章

  1. centos7 安装mariaDB 以及 phpmyadmin的安装

    centos7 安装mariaDB 以及 phpmyadmin的安装 一:安装mariadb, mariadb 是 mysql 的一个分支,基本和mysql一样的 1. yum -y install ...

  2. centos7 安装Mariadb

    MariaDB 数据库管理系统是 MySQL 的一个分支,主要由开源社区在维护,采用 GPL 授权许可.开发这个分支的原因之一是:甲骨文公司收购了 MySQL 后,有将 MySQL 闭源的潜在风险,因 ...

  3. CentOS7安装MariaDB成功的实践

    前言 在自己的VPS的CentOS7安装Oracle的Mysql失败以后,我又开始找CentOS7上面安装MariaDB的方法,于是我找打了这篇文章:http://blog.csdn.net/defa ...

  4. centos7安装MariaDB以及Failed to start mariadb.service: Unit not found的错误解决

    centos7下yum安装MariaDB CentOS 7下mysql下替换成MariaDB了.MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权 许可 Mari ...

  5. centos7 安装mariadb、"systemctl status mariadb.service" and "journalctl -xe" for details

    centos7 mariadb 安装 也可解决此错误:ob for mariadb.service failed because the control process exited with err ...

  6. centos7安装mariadb后无法启动的问题

    MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可.开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方 ...

  7. 5.CentOS7安装mariadb

    MariaDB 和 MySQL 使用是一样的,二者只要安装一个就行了 MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可.开发这个分支的原因之一是:甲骨文公司 ...

  8. centos7安装mariadb

    ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) 1.官方um安装mariadb 1).准备官方yum [mariadb ...

  9. centos7 安装 mariadb 的正确命令

    使用的是linode的centos7系统,安装mysql发现已经默认的是mariadb. 但是不管是使用linode官网说明还是百度搜索到的的根本安装方法无法安装成功. 总是提示这一句: ERROR  ...

随机推荐

  1. Git-第二篇廖雪峰Git教程学习笔记(1)基本命令,版本回退

    1.安装Git-2.16.2-64-bit.exe后,设置用户名,用户邮箱 #--global参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然也可以对某个仓库指定不同的用户名和Email地 ...

  2. 搜索(BFS)---完美平方数

    完美平方数 279. Perfect Squares (Medium) For example, given n = 12, return 3 because 12 = 4 + 4 + 4; give ...

  3. spark复习笔记(5):API分析

    0.spark是基于hadoop的mr模型,扩展了MR,高效实用MR模型,内存型集群计算,提高了app处理速度. 1.特点:(1)在内存中存储中间结果 (2)支持多种语言:java scala pyt ...

  4. node中使用log4js4.x版本记录

    const log4js = require('log4js'); log4js.configure({ appenders: { logFile: { //文件形式打印日志 type: " ...

  5. 利用JFreeChart生成简单柱状图(Java)

    package barchartdemo1; import <a href="http://lib.csdn.net/base/javaee" class='replace_ ...

  6. unity2017 光照与渲染(一)

    光照&渲染(基于unity2017.2.0) Custom Skybox 天空盒 最丰富的环境光 a. TextureShape 改成 Cube. b. 把图片直接丢给天空,就会自动生成材质. ...

  7. tenorflow 模型调优

    # Create the Timeline object, and write it to a json from tensorflow.python.client import timeline t ...

  8. 2018ICPC银川 L Continuous Intervals 单调栈 线段树

    题意:给你一个序列,问你这个序列有多少个子区间,满足把区间里的数排序之后相邻两个数之间的差 <= 1 ? 思路:https://blog.csdn.net/u013534123/article/ ...

  9. Linux telnet、nc、ping监测状态

    在工作中会遇到网络出现闪断丢包的情况,最终影响业务工常使用.可以业务服务器上发起监测. 1.通过telnet echo  -e  "\n" | telnet localhost 2 ...

  10. bzoj4543 [POI2014]Hotel加强版 长链剖分+树形DP

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4543 题解 这道题的弱化版 bzoj3522 [POI2014]Hotel 的做法有好几种吧. ...