在Centos 7上安装Mariadb
Huangzhongbang
・3 分钟阅读
从MySQL分支出来,众所周知,MariaDB是一种直接替代品,可以对MySQL进行增强和性能优化。本教程将向你展示如何以两种不同的方式将Mariadb安装到Centos7上。
步骤1下载/安装Mariadb
从仓库安装
MariaDB自CentOS 7开始在CentOS仓库中提供,任何较低的产品都需要您将额外的存储库添加到您的服务器。在你的服务器上运行以下命令:
yum update -y
yum install mariadb-server
你还可能需要通过运行以下命令来完成安装:
/usr/bin/mysql_secure_installation
这会安装MariaDB,并且引导你完成设置root密码的过程。
MariaDB镜像的手动安装(最新版本)
这是简单明了的你需要在/etc/yum.repos.d/
中创建一个文件,并添加以下内容:
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
创建文件后,运行以下命令:
yum update -y
yum install MariaDB-server MariaDB-client
然后,你可以通过运行以下命令完成安装:
/usr/bin/mysql_secure_installation
如果一切顺利,进入下一步。
步骤2验证Mariadb是否可运行
根据你使用的是CentOS 7的默认镜像还是使用自定义ISO,你可能需要手动启动MariaDB,并且在服务器启动时启用它,要执行这个操作,请运行:
systemctl start mariadb.service
systemctl enable mariadb.service
执行以下命令可以检查所有内容是否都在运行:
systemctl is-active mariadb.service
安装后,运行 mysql -u root -p
提示时输入密码,你将看到类似以下内容的输出:
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is XXXX
Server version: 5.5.X
Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB [(none)]>
恭喜你,你已在CentOS 7上成功安装了Mariadb,如果在连接方面出现错误,请通过重复步骤2的开头来确保Mariadb正在运行,享受吧!