CentOS 7にMarialDBをインストールする

3383 ワード

シーケンス
MysqlがOracleによって買収されたため、CentOS 7のデフォルトではMarialDB 5.5.2をインストールできます.最新のバージョンをインストールする場合は、インストールソースを自分で設定する必要があります.ここでは主にデフォルトバージョンについて説明します.
su -
rpm -qa | grep mariadb
yum remove mysql mysql-server mysql-libs compat-mysql51
rpm -e --nodeps mariadb-*

vim /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.1 CentOS repository list - created 2017-02-15 20:31 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

yum -y install MariaDB-server MariaDB-client

インストール
yum -y install mariadb mariadb-server
#    MariaDB,    MariaDB
systemctl start mariadb
#      
systemctl enable mariadb
#     MariaDB       
mysql_secure_installation
#       ,        
Enter current password for root (enter for none):

MariaDBの文字セットの設定
#  /etc/my.cnf
vi /etc/my.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/client.cnf
vi /etc/my.cnf.d/client.cnf
# [client]   
default-character-set=utf8

#  /etc/my.cnf.d/mysql-clients.cnf
vi /etc/my.cnf.d/mysql-clients.cnf
# [mysql]   
default-character-set=utf8

#      ,  mariadb
systemctl restart mariadb

#  MariaDB     
mysql> 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 [mysql]> select version();
+----------------+
| version()      |
+----------------+
| 5.5.52-MariaDB |
+----------------+
1 row in set (0.00 sec)

ユーザーの追加、権限の設定
#      
mysql>create user username@localhost identified by 'password';
#            
mysql>grant all on *.* to username@localhost indentified by 'password';
#         
mysql>grant all privileges on *.* to username@'%' identified by 'password';
#          
mysql>grant all privileges on *.* to username@'hostname' identified by 'password' with grant option;
#                。
#              all privileges  all  select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file     。