在本教程中,我们将向您展示如何在您的 CentOS 6 服务器上安装和配置 MariaDB。 对于那些不知道的人, 玛丽亚数据库 是 MySQL 的直接替代品。 它易于安装,提供许多速度和性能改进,并且易于集成到大多数 MySQL 部署中。 MariaDB 被广泛使用,一些 Linux 发行版和大公司已经从 MySQL 切换到 MariaDB。
本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户下运行,如果不是,您可能需要添加 ‘sudo
‘ 到命令以获取 root 权限。 我将向您展示在 CentOS 6 上逐步安装 MariaDB 数据库。
先决条件
- 运行以下操作系统之一的服务器:CentOS 6。
- 建议您使用全新的操作系统安装来防止任何潜在问题。
- 对服务器的 SSH 访问(或者如果您在桌面上,则只需打开终端)。
- 一种
non-root sudo user
或访问root user
. 我们建议充当non-root sudo user
,但是,如果您在充当 root 时不小心,可能会损害您的系统。
在 CentOS 6 上安装 MariaDB
第 1 步。首先,您需要在系统上启用存储库。
导航 /etc/yum.repos.d/
在您的 CentOS 机器上并创建一个名为 MariaDB repo 的新文件。
## RHEL/CentOS 6 64-Bit ## [mariadb] name = MariaDB baseurl = https://yum.mariadb.org/5.5/centos6-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 ## RHEL/CentOS 6 32-Bit ## [mariadb] name = MariaDB baseurl = https://yum.mariadb.org/5.5/centos6-x86 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
步骤 2. 在 CentOS 6 上安装 MariaDB。
使用 yum 安装 MariaDB:
yum update yum install -y MariaDB-server MariaDB-client MariaDB-devel
安装完成后,启动 MariaDB:
service mysql start
将 MariaDB 设置为开机启动:
chkconfig mysql on
步骤 3. 配置 MariaDB。
MariaDB 的配置文件和二进制文件大部分与 MySQL 相同。 例如,两者都使用一个名为 my.cnf
.
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
步骤 4. 安装后保护 MariaDB。
默认情况下,MariaDB 未加固。 您可以使用 mysql_secure_installation 脚本保护 MariaDB。 您应该仔细阅读下面的每个步骤,这些步骤将设置 root 密码,删除匿名用户,禁止远程 root 登录,并删除测试数据库和对安全 MariaDB 的访问。
# mysql_secure_installation /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found 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! [root@idroot]#
步骤 5. 登录 MariaDB。
使用之前设置的根凭证登录 MariaDB。
mysql -u root -p
恭喜! 您已成功安装 MariaDB。 感谢您使用本教程在 CentOS 6 系统中安装 MariaDB。 如需更多帮助或有用信息,我们建议您查看 MariaDB 官方网站。