因为ipa服务和mysql的冲突,我就安装了MariaDB服务器。
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。在存储引擎方面,使用XtraDB(英语:XtraDB)来代替MySQL的InnoDB。
MariaDB基于事务的Maria存储引擎,替换了MySQL的MyISAM存储引擎,它使用了Percona的 XtraDB,InnoDB的变体,分支的开发者希望提供访问即将到来的MySQL 5.4 InnoDB性能。这个版本还包括了 PrimeBase XT (PBXT) 和 FederatedX存储引擎。
CentOS 6 或早期的版本中提供的是 MySQL 的服务器/客户端安装包,但 CentOS 7 已使用了 MariaDB 替代了默认的 MySQL。MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。
MySQL 已经不再包含在 CentOS 7 的源中,而改用了 MariaDB;
1.使用rpm -qa | grep mariadb搜索 MariaDB 现有的包:
如果存在,使用rpm -e --nodeps mariadb-*全部删除:
[root@ipa ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@ipa ~]# rpm -e mysql-*
2.使用rpm -qa | grep mariadb搜索 MariaDB 现有的包:
如果存在,使用yum remove mysql mysql-server mysql-libs compat-mysql51全部删除;
[root@ipa ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@ipa ~]# yum remove mysql mysql-server mysql-libs compat-mysql51
卸载完毕!
[root@ipa ~]# rpm -qa | grep mariadb
[root@ipa ~]#
3.开始新的安装, 下载mysql压缩包并解压,创建MariaDB.repo文件
[root@ipa ~]# tar -xvf mysql-8.0.15-1.el7.x86_64.rpm-bundle.tar
配置mariadb.repo文件
[root@ipa ~]# vi /etc/yum.repos.d/maraidb.repo
[mariadb]
name=mariadb
baseurl=file:///root/mysql-8.0.15-1.el7.x86_64.rpm-bundle/
gpgcheck=0
[root@ipa ~]# yum makecache
Loaded plugins: fastestmirror, langpacks
dvd | 3.6 kB 00:00
mariadb | 2.9 kB 00:00
(1/5): mariadb/filelists_db | 112 kB 00:00
(2/5): mariadb/other_db | 6.8 kB 00:00
(3/5): dvd/other_db | 2.5 MB 00:00
(4/5): mariadb/primary_db | 22 kB 00:00
(5/5): dvd/filelists_db | 6.7 MB 00:01
Loading mirror speeds from cached hostfile
Metadata Cache Created
4.安装mariadb和mariadb-server
[root@ipa ~]# yum install -y mariadb mariadb-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.56-2.el7 will be installed
---> Package mariadb-server.x86_64 1:5.5.56-2.el7 will be installed
--> Processing Dependency: perl-DBD-MySQL for package: 1:mariadb-server-5.5.56-2.el7.x86_64
--> Running transaction check
---> Package perl-DBD-MySQL.x86_64 0:4.023-5.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
mariadb x86_64 1:5.5.56-2.el7 dvd 8.7 M
mariadb-server x86_64 1:5.5.56-2.el7 dvd 11 M
Installing for dependencies:
perl-DBD-MySQL x86_64 4.023-5.el7 dvd 140 k
Transaction Summary
================================================================================
Install 2 Packages (+1 Dependent package)
Total download size: 20 M
Installed size: 107 M
Downloading packages:
--------------------------------------------------------------------------------
Total 51 MB/s | 20 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 1:mariadb-5.5.56-2.el7.x86_64 1/3
Installing : perl-DBD-MySQL-4.023-5.el7.x86_64 2/3
Installing : 1:mariadb-server-5.5.56-2.el7.x86_64 3/3
Verifying : 1:mariadb-server-5.5.56-2.el7.x86_64 1/3
Verifying : perl-DBD-MySQL-4.023-5.el7.x86_64 2/3
Verifying : 1:mariadb-5.5.56-2.el7.x86_64 3/3
Installed:
mariadb.x86_64 1:5.5.56-2.el7 mariadb-server.x86_64 1:5.5.56-2.el7
Dependency Installed:
perl-DBD-MySQL.x86_64 0:4.023-5.el7
Complete!
5.启动MariaDB服务
[root@ipa ~]# systemctl start mariadb
[root@ipa ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@ipa ~]# 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 <– 是否设置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] <– 是否删除匿名用户,回车
... 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] <–是否禁止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] <– 是否删除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] <– 是否重新加载权限表,回车
... 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@ipa ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> exit
Bye
6.配置MariaDB的字符集
查看/etc/my.cnf文件内容,其中包含一句!includedir /etc/my.cnf.d 说明在该配置文件中引入/etc/my.cnf.d 目录下的配置文件。
1)使用vi server.cnf命令编辑server.cnf文件,在[mysqld]标签下添加
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
如果/etc/my.cnf.d 目录下无server.cnf文件,则直接在/etc/my.cnf文件的[mysqld]标签下添加以上内容。
2)文件/etc/my.cnf.d/client.cnf,在[client]中添加
vi /etc/my.cnf.d/client.cnf
[client]
default-character-set=utf8
[client-mariadb]
3)文件/etc/my.cnf.d/mysql-clients.cnf
[root@ipa ~]# vi /etc/my.cnf.d/mysql-clients.cnf
[mysql]
default-character-set=utf8
全部配置完成,重启mariadb
systemctl restart mariadb
之后进入MariaDB查看字符集
[root@ipa ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show variables like "%character%";show variables like "%collation%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database | utf8_unicode_ci |
| collation_server | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
MariaDB [(none)]>