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. Web API 入门三(参数绑定)

    学到现在,感觉到微软的.NET各种框架和模型基础大致都差不多,所以,这部分内容大致和MVC部分差不多.在学习参事绑定之前,我们肯定要知道Controller(即控制器)是啥干啥的. 其实,Contro ...

  2. Oracle数据库的发展历程

    前言 1970年的6月,IBM 公司的研究员埃德加·考特 (Edgar Frank Codd) 在 Communications of ACM 上发表了那篇著名的<大型共享数据库数据的关系模型& ...

  3. python-docx 添加表格时很慢的解决方法

    我们做监控系统的时候常需要给客户发送邮箱报告,附带一个word的文档,文档中插入表格给用户更直观的数据. 我用的时python-docx库操作文档,最近碰到,当往文档中插入表格时,随着表格行数的增多, ...

  4. R语言常用数据管理

    1.变量的重命名 (1)交互式编辑器修改变量名 若要修改数据集x中的变量名,键入fix(x)即可打开交互式编辑器的界面.若数据集为矩阵或数据框,单击交互式编辑器界面中对应要修改的变量名,可手动输入新的 ...

  5. PCIe基础篇(一)、基础知识扫盲

    1.PCIe:Peripheral Component interconnect Expess,外围组件接口互联,属于第三代IO总线,PCIe的传输速率指的是实际的有效传输速率,为RAW data(原 ...

  6. JCTF 2014 小菜一碟

    测试文件:https://static2.ichunqiu.com/icq/resources/fileupload//CTF/JCTF2014/re100 1.准备 获得信息 ZIP文件 Java文 ...

  7. UNIX网络编程总结四

    socket: 为了执行网络I/O,一个进程做的第一件事就是调用socket函数. family指明协议族,type指明类型,除非在原始套接口,protocol一般为0,并非所有的family,typ ...

  8. sigprocmask()函数学习笔记

    sigprocmask()函数用于改变进程的当前阻塞信号集,也可以用来检测当前进程的信号掩码. 函数原型: int sigprocmask(int how, const sigset_t *restr ...

  9. Ubuntu环境下SSH服务安装、SSH远程登录以及SSH数据传输

    https://www.cnblogs.com/asyang1/p/9467646.html SSH 为 Secure Shell 的缩写,为建立在应用层基础上的安全通信协议. 一.检查SSH服务是否 ...

  10. springboot--异步执行的方法及定时执行的方法

    让方法被调用后异步的执行 一般来说,要异步执行一个任务都是创建一个线程来专门干这个任务.在springboot中有 @Async 这个注解快速实现方法的异步执行.只需要两步:第一步: 在启动类上加上@ ...