以下流程亲测已过
[root@dbServer ~]# yum install -y mariadb mariadb-server
已加载插件:fastestmirrorLoading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 mariadb.x86_64.1.5.5.52-1.el7 将被 安装
--> 正在处理依赖关系 mariadb-libs(x86-64) = 1:5.5.52-1.el7,它被软件包 1:mariadb-5.5.52-1.el7.x86_64 需要
---> 软件包 mariadb-server.x86_64.1.5.5.52-1.el7 将被 安装
--> 正在处理依赖关系 perl-DBD-MysqL,它被软件包 1:mariadb-server-5.5.52-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.52-1.el7 将被 安装
---> 软件包 perl-DBD-MysqL.x86_64.0.4.023-5.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
====================================================================================
Package 架构 版本 源 大小
=============================================================================================================================
正在安装:
mariadb x86_64 1:5.5.52-1.el7 base 8.7 M
mariadb-server x86_64 1:5.5.52-1.el7 base 11 M
为依赖而安装:
mariadb-libs x86_64 1:5.5.52-1.el7 base 761 k
perl-DBD-MysqL x86_64 4.023-5.el7 base 140 k
事务概要
==============================================================================================================================
安装 2 软件包 (+2 依赖软件包)
总下载量:20 M
安装大小:109 M
Downloading packages:
(1/4): mariadb-libs-5.5.52-1.el7.x86_64.rpm | 761 kB 00:00:00
(2/4): mariadb-5.5.52-1.el7.x86_64.rpm | 8.7 MB 00:00:08
(3/4): perl-DBD-MysqL-4.023-5.el7.x86_64.rpm | 140 kB 00:00:00
(4/4): mariadb-server-5.5.52-1.el7.x86_64.rpm | 11 MB 00:00:10
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 1.8 MB/s | 20 MB 00:00:11
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : 1:mariadb-libs-5.5.52-1.el7.x86_64 1/4
正在安装 : perl-DBD-MysqL-4.023-5.el7.x86_64 2/4
正在安装 : 1:mariadb-5.5.52-1.el7.x86_64 3/4
正在安装 : 1:mariadb-server-5.5.52-1.el7.x86_64 4/4
验证中 : 1:mariadb-server-5.5.52-1.el7.x86_64 1/4
验证中 : perl-DBD-MysqL-4.023-5.el7.x86_64 2/4
验证中 : 1:mariadb-5.5.52-1.el7.x86_64 3/4
验证中 : 1:mariadb-libs-5.5.52-1.el7.x86_64 4/4
已安装:
mariadb.x86_64 1:5.5.52-1.el7 mariadb-server.x86_64 1:5.5.52-1.el7
作为依赖被安装:
mariadb-libs.x86_64 1:5.5.52-1.el7 perl-DBD-MysqL.x86_64 0:4.023-5.el7
完毕!
[root@dbServer ~]#
[root@dbServer ~]# systemctl start mariadb
[root@dbServer ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@dbServer ~]#
[root@dbServer ~]# 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
Goa 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]n
... 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]n
... skipping.
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@dbServer ~]#MySQL-uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000,2016,Oracle,MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
MariaDB [(none)]>show variables like "%character%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/MysqL/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
字符集备注:
character_set_client:客户端请求数据的字符集。
character_set_connection:从客户端接收到数据,然后传输的字符集。
character_set_database:默认数据库的字符集,无论默认数据库如何改变,都是这个字符集;如果没有默认数据库,使character_set_server指定的字符集,此参数无需设置。
character_set_filesystem:把character_set_client转换character_set_filesystem,默认binary即可。
character_set_results:结果集的字符集。
character_set_server:数据库服务器的默认字符集。
character_set_system:这个值总是utf8,不需要设置,存储系统元数据的字符集
MariaDB [(none)]>set character_set_database=utf8;
Query OK,0 rows affected (0.00 sec)
MariaDB [(none)]>set character_set_server=utf8;
Query OK,0 rows affected (0.00 sec)
MariaDB [(none)]> create database jobHunter;
Query OK,1 row affected (0.00 sec)
MariaDB [(none)]> use jobHunter;
Database changed
MariaDB [jobHunter]> source /root/createtable.sql
Query OK,0 rows affected (0.01 sec)
可能存在问题:
如下,也就是可能SET character_set_database = utf8;命令失效
MariaDB [(none)]> SET character_set_database = utf8;
Query OK,0 rows affected (0.00 sec)
MariaDB [(none)]> commit;
Query OK,0 rows affected (0.00 sec)
MariaDB [(none)]> show variables like "%character%";
+--------------------------+----------------------------+
| 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)
MariaDB [(none)]> exit
Bye
[root@hadron ~]# MysqL -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000,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%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/MysqL/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
[root@hadron /]#vi /etc/my.cnf
[MysqLd]
character-set-server=utf8
datadir=/var/lib/MysqL
socket=/var/lib/MysqL/MysqL.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run MysqLd under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[MysqLd_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[client]
default-character-set=utf8
[MysqL]
default-character-set=utf8
[root@hadron /]#systemctl restart mariadb [root@hadron /]# MysqL -uroot -p123456 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000,MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show variables like "%collation%"; +----------------------+-----------------+ | Variable_name | Value | +----------------------+-----------------+ | collation_connection | utf8_general_ci | | collation_database | utf8_general_ci | | collation_server | utf8_general_ci | +----------------------+-----------------+ 3 rows in set (0.00 sec) MariaDB [(none)]> show variables like "%character%"; +--------------------------+----------------------------+ | 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) MariaDB [(none)]>