如何在 Ubuntu 14.04 上安装 MariaDB

在本教程中,我们将向您展示如何在 Ubuntu 14.04 上安装 MariaDB。 对于那些不知道的人,MariaDB 是 MySQL 的替代品。 它易于安装,提供许多速度和性能改进,并且易于集成到大多数 MySQL 部署中。 MariaDB 被广泛使用,一些 Linux 发行版和大公司已经从 MySQL 切换到 MariaDB。

本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户下运行,如果不是,您可能需要添加 ‘sudo‘ 到命令以获取 root 权限。 安装非常简单。 我将向您展示在 Ubuntu 14.04 上逐步安装 MariaDB。

先决条件

  • 运行以下操作系统之一的服务器:Ubuntu 14.04。
  • 建议您使用全新的操作系统安装来防止任何潜在问题。
  • 对服务器的 SSH 访问(或者如果您在桌面上,则只需打开终端)。
  • 一种 non-root sudo user或访问 root user. 我们建议充当 non-root sudo user,但是,如果您在充当 root 时不小心,可能会损害您的系统。

在 Ubuntu 14.04 上安装 MariaDB

第 1 步:首先需要启用 MariaDB 存储库。

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db

步骤 2. MariaDB 的安装。

导入密钥并添加存储库后,您可以使用以下命令安装 MariaDB:

apt-get update
apt-get install mariadb-server

在安装时,MariaDB 会询问用户 root 的密码。 Enter 密码并确保不要忘记。

步骤 3. 安装后保护 MariaDB。

默认情况下,MariaDB 未加固。 您可以使用 mysql_secure_installation 脚本保护 MariaDB。 您应该仔细阅读下面的每个步骤,这些步骤将设置 root 密码,删除匿名用户,禁止远程 root 登录,并删除测试数据库和对安全 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!
[root@idroot]#

步骤 4. 启动 MariaDB 服务。

service mysql start

步骤 5. 登录 MariaDB。

完成安装后,您可以使用以下命令连接到 MariaDB。

mysql -u root -p

恭喜! 您已成功安装 MariaDB。 感谢您使用本教程在 Ubuntu 14.04 上安装 MariaDB 数据库管理系统。 如需其他帮助或有用信息,我们建议您查看 MariaDB 官方网站.

Save