Centos6下使用yum安裝MariaDB

散盡浮華發表於2018-03-13

 

1)增加mariaDB的yum源

[root@centos6-test08 ~]# cd /etc/yum.repos.d/
[root@centos6-test08 yum.repos.d]# cp CentOS-Base.repo CentOS-Base.repo.bak
[root@centos6-test08 yum.repos.d]# vim CentOS-Base.repo
......
[mariadb]    
name = MariaDB
baseurl = http://yum.mariadb.org/10.3.5/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB   
gpgcheck=1

2)yum安裝MariaDB

[root@centos6-test08 yum.repos.d]# yum install -y MariaDB-server MariaDB MariaDB-client

安裝好後,啟動服務
[root@centos6-test08 yum.repos.d]# /etc/init.d/mysql start
[root@centos6-test08 yum.repos.d]# ps -ef|grep mysql
[root@centos6-test08 yum.repos.d]# lsof -i:3306

設定開機啟動
[root@centos6-test08 yum.repos.d]# chkconfig mysql on

[root@centos6-test08 yum.repos.d]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.5-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)]>

3)接下來進行MariaDB的相關簡單配置,設定密碼,會提示先輸入密碼

[root@centos6-test08 yum.repos.d]# 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):      <–初次執行直接回車
  
設定密碼
Set root password? [Y/n]                               <– 是否設定root使用者密碼,輸入y並回車或直接回車
New password:                                          <– 設定root使用者的密碼,比如密碼為123456
Re-enter new password:                                 <– 再輸入一次你設定的密碼
  
其他配置
Remove anonymous users? [Y/n]                          <– 是否刪除匿名使用者,回車
Disallow root login remotely? [Y/n]                    <–是否禁止root遠端登入,回車,
Remove test database and access to it? [Y/n]           <– 是否刪除test資料庫,回車
Reload privilege tables now? [Y/n]                     <– 是否重新載入許可權表,回車

[root@centos6-test08 yum.repos.d]# mysql -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 10.3.5-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)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.001 sec)

4)接下來配置MariaDB的字符集

[root@centos6-test08 yum.repos.d]# cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d                              //說明在該配置檔案中引入/etc/my.cnf.d 目錄下的配置檔案

[root@centos6-test08 yum.repos.d]# ls /etc/my.cnf.d/
enable_encryption.preset  mysql-clients.cnf  server.cnf

首先是配置檔案/etc/my.cnf.d/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/mysql-clients.cnf,在[mysql]中新增
default-character-set=utf8

最後是重啟MariaDB,並登陸MariaDB檢視字符集
[root@centos6-test08 yum.repos.d]# /etc/init.d/mysql restart
Shutting down MariaDB.. SUCCESS! 
Starting MariaDB.180313 05:47:41 mysqld_safe Logging to '/var/lib/mysql/centos6-test08.err'.
180313 05:47:41 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
 SUCCESS! 

[root@centos6-test08 yum.repos.d]# mysql -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.5-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)]> 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.001 sec)

+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database   | utf8_unicode_ci |
| collation_server     | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.001 sec)

相關文章