如何安装MariaDB 5.5在CentOS, RHEL 7/6使用Yum

时间:2019-05-29 14:48:03  来源:igfitidea点击:

MariaDB一个增强的,替换MySQL的工具。
对于数据库专业人员来说,MariaDB是一个寻找 健壮可扩展可靠SQL服务器的更好的选择。

本文将使用Yum在CentOS、RHEL 6/5和Fedora 19/18/17系统中安装MariaDB 5.5

第1步:添加MariaDB Yum存储库

首先,我们需要在系统中添加MariaDB yum存储库。

创建一个新的 /etc/yum.repos.d/mariadb.repo文件
并根据操作系统和架构添加下面的内容。

用于CentOS/RHEL 7(64位)

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

用于CentOS/RHEL 6(64位)

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

步骤2:安装MariaDB

使用以下命令在系统上安装MariaDB

# yum install MariaDB-server MariaDB-client

第三步:启动MariaDB服务

在系统中安装MariaDB之后,让我们使用以下命令启动服务。

# service mysql start

步骤4:MariaDB安全性设置

最后,我们需要用密码保护MariaDB的安装,并做一些其他更改。
为此,从命令行运行安全安装脚本。

# mysql_secure_installation

安全安装脚本会要求用户回答一些问题,按照下面的输出显示的安装。

$ /usr/bin/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, well need the current
password for the root user.  If youve just installed MariaDB, and
you havent 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): [Press Enter]
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: [Enter Password Here]
Re-enter new password: [Re-enter Password Here]
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 youve completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

步骤5:验证连接

安装MariaDB后,使用以下命令连接到MariaDB服务器

#  mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 9
Server version: 5.5.34-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>