Mariadb及phpmyadmin的安装及配置(Centos 7)

CentOS 6 或早期的版本中提供的是 MySQL 的服务器/客户端安装包,但 CentOS 7 已使用了 MariaDB 替代了默认的 MySQL。MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。

全部删除MySQL/MariaDB

MySQL 已经不再包含在 CentOS 7 的源中,而改用了 MariaDB;

1.使用rpm -qa | grep mariadb搜索 MariaDB 现有的包

[[email protected] ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
mariadb-server-5.5.60-1.el7_5.x86_64
mariadb-5.5.60-1.el7_5.x86_64
[[email protected] ~]# 

Mariadb及phpmyadmin的安装及配置(Centos 7)
如果存在,使用yum remove mysql mysql-server mysql-libs compat-mysql51全部删除

[[email protected] ~]# yum remove mysql mysql-server mysql-libs compat-mysql51
Loaded plugins: fastestmirror, langpacks
No Match for argument: mysql-server
No Match for argument: compat-mysql51
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.60-1.el7_5 will be erased
--> Processing Dependency: mariadb(x86-64) = 1:5.5.60-1.el7_5 for package: 1:mariadb-serv  
......(省略)
Removed:
  mariadb.x86_64 1:5.5.60-1.el7_5          mariadb-libs.x86_64 1:5.5.60-1.el7_5

Dependency Removed:
  mariadb-server.x86_64 1:5.5.60-1.el7_5       perl-DBD-MySQL.x86_64 0:4.023-6.el7
  php-mysql.x86_64 0:5.4.16-46.el7             phpMyAdmin.noarch 0:4.4.15.10-3.el7
  postfix.x86_64 2:2.10.1-6.el7

Complete!

[[email protected] ~]# 

Mariadb及phpmyadmin的安装及配置(Centos 7)
再次搜索,已全部删除。

[[email protected] ~]# rpm -qa | grep mariadb
[[email protected] ~]# 

3.mariadb安装前准备:配置yum源:

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo(阿里云yum源)

[[email protected] ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2523  100  2523    0     0  13676      0 --:--:-- --:--:-- --:--:-- 13711
[[email protected] ~]#

4. 进入/etc/yum.repos.d/目录下,编辑 epel.repo 文件

[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# cat epel.repo
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/7Server/x86_64/
gpgcheck=0
[[email protected] yum.repos.d]#

5. 安装mariadbmasriadb-server

[[email protected] ~]# yum install -y mariadb masriadb-server
Loaded plugins: fastestmirror, langpacks
base                                                                           | 3.6 kB  00:00:00
extras                                                                         | 3.4 kB  00:00:00
updates                                                                        | 3.4 kB  00:00:00
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
......(省略)
Installed:
  mariadb.x86_64 1:5.5.60-1.el7_5

Dependency Installed:
  mariadb-libs.x86_64 1:5.5.60-1.el7_5

Complete!
[[email protected] ~]#

6. 启动服务

[[email protected] ~]# systemctl start mariadb
[[email protected] ~]# systemctl enable mariadb

7. 对mariadb进行安全配置 :mariadb_secure_installation

设置 MariaDB 的 root 账户密码,删除匿名用户,禁用 root 远程登录,删除测试数据库,重新加载权限表。

[[email protected] ~]# 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.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] y  <– 是否设置root用户密码,输入y并回车或直接回车
New password:   <– 设置root用户的密码
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    <–是否禁止root远程登录
 ... 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   <– 是否删除test数据库
 - 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!
[[email protected] ~]#

8. 初始化MariaDB完成,接下来测试登录,通过命令行登录:mysql -uroot -p

[[email protected] ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>

9. 进入到mysql中查询数据库信息

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> exit
Bye
[[email protected] ~]#

10. 安装phpmyadmin的包

[[email protected] ~]# yum  install php php-mcrypt httpd mod_ssl phpmyadmin -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
......(省略)
Running transaction
  Installing : php-mysql-5.4.16-46.el7.x86_64                                                     1/2
  Installing : phpMyAdmin-4.4.15.10-3.el7.noarch                                                  2/2
  Verifying  : phpMyAdmin-4.4.15.10-3.el7.noarch                                                  1/2
  Verifying  : php-mysql-5.4.16-46.el7.x86_64                                                     2/2

Installed:
  phpMyAdmin.noarch 0:4.4.15.10-3.el7

Dependency Installed:
  php-mysql.x86_64 0:5.4.16-46.el7

Complete!
[[email protected] ~]#

11. 进入/etc/httpd/conf.d/目录下,编辑 phpMyAdmin.conf 文件

[[email protected] ~]# cd /etc/httpd/conf.d/
[[email protected] conf.d]# ls
autoindex.conf  php.conf  phpMyAdmin.conf  README  ssl.conf  userdir.conf  welcome.conf
[[email protected] conf.d]# vi phpMyAdmin.conf
[[email protected] conf.d]#

修改第17和34行

Require  ip   127.0.0.1    192.168.91.0/24 

12. 重启httpd服务

[[email protected] conf.d]# systemctl retsart httpd
[[email protected] conf.d]# systemctl enable httpd

13. 打开浏览器输入:http://192.168.91.135/phpMyAdmin
Mariadb及phpmyadmin的安装及配置(Centos 7)
Mariadb及phpmyadmin的安装及配置(Centos 7)