Centos7.x版本下針對Mysql的安裝和使用多少跟之前的Centos6之前版本有所不同的,廢話就不多贅述了,下面介紹下在centos7.x環境裡安裝mysql5.7的幾種方法:
一、yum方式安裝
Centos7.x版本下針對Mysql的安裝和使用多少跟之前的Centos6之前版本有所不同的,廢話就不多贅述了,下面介紹下在centos7.x環境裡安裝mysql5.7的幾種方法: 一、yum方式安裝 從CentOS 7.0釋出以來,yum源中開始使用Mariadb來代替MySQL的安裝。即使你輸入的是yum install -y mysql , 顯示的也是Mariadb的安裝內容。 使用原始碼進行編譯安裝又太麻煩。因此,如果想使用yum安裝MySQL的話,就需要去下載官方指定的yum源. yum下載網址為:https://dev.mysql.com/downloads/repo/yum/ 找到Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package,單擊後面的Download, 在新的頁面中單擊最下面的No thanks, just start my download.就可以下載到yum源了。 1)安裝MySQL YUM資源庫 [root@kevin ~]# yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 2)安裝MySQL 5.7 [root@kevin ~]# yum install -y mysql-community-server 3)啟動MySQL伺服器和MySQL的自動啟動 [root@kevin ~]# systemctl start mysqld.service [root@kevin ~]# systemctl enable mysqld.service 4)密碼問題 由於MySQL從5.7開始不允許首次安裝後使用空密碼進行登入!為了加強安全性,系統會隨機生成一個密碼以供管理員首次登入使用, 這個密碼記錄在/var/log/mysqld.log檔案中,使用下面的命令可以檢視此密碼: [root@kevin ~]# cat /var/log/mysqld.log|grep 'A temporary password' 2018-01-24T02:32:20.210903Z 1 [Note] A temporary password is generated for root@localhost: DOqInortw9/< 最後一行冒號後面的部分DOqInortw9/<就是初始密碼。 使用此密碼登入MySQL: [root@kevin ~]# mysql -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.21 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 使用隨機生產的密碼登入到服務端後,必須馬上修改密碼,不然會報如下錯誤: mysql> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. 有兩種方法解決上面的報錯(如下的123456是修改後的密碼): mysql> set password=password("123456"); 或者 mysql> alter user 'root'@'localhost' identified by '123456'; 重新整理許可權 mysql> flush privileges; =============================================================================================== 如果上面在執行set password=password("123456");命令後出現下面的報錯: ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 解決辦法: 這個與Mysql 密碼安全策略validate_password_policy的值有關,validate_password_policy可以取0、1、2三個值: 0 or LOW Length 1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters 2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary 預設的數值是1,符合長度,且必須含有數字,小寫或大寫字母,特殊字元。 所以剛開始設定的密碼必須符合長度,且必須含有數字,小寫或大寫字母,特殊字元。 有時候,只是為了自己測試,不想密碼設定得那麼複雜,譬如說,我只想設定root的密碼為123456。 必須修改兩個全域性引數: mysql> set global validate_password_policy=0; Query OK, 0 rows affected (0.00 sec) mysql> set global validate_password_length=1; Query OK, 0 rows affected (0.00 sec) 修改上面兩個引數後,就可以解決這個報錯了。 ======================================================================================================= 注意一點: mysql5.7之後的資料庫裡mysql.user表裡已經沒有password這個欄位了,password欄位改成了authentication_string。 所以修改密碼的命令如下: mysql> update mysql.user set authentication_string=password('kevin@123') where user='root'; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> ======================================================================================================= 檢視mysql版本 mysql> select version(); +-----------+ | version() | +-----------+ | 5.7.21 | +-----------+ 1 row in set (0.00 sec) mysql> ======================================================================================================= 修改mysql5.7的編碼由latin1為utf8 預設編碼: mysql> show variables like "%character%";show variables like "%collation%"; +--------------------------+----------------------------+ | 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) +----------------------+-------------------+ | Variable_name | Value | +----------------------+-------------------+ | collation_connection | utf8_general_ci | | collation_database | latin1_swedish_ci | | collation_server | latin1_swedish_ci | +----------------------+-------------------+ 3 rows in set (0.01 sec) 調整操作: [root@kevin ~]# cat /etc/my.cnf ...... [mysqld] ...... character-set-server=utf8 //注意這個不能寫成default-character-set=utf8,否則會導致5.7版本mysql無法開啟 [client] default-character-set=utf8 [root@kevin~]# systemctl restart mysqld.service [root@kevin~]# mysql -p ...... 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.01 sec) +----------------------+-----------------+ | 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) mysql>
二、RPM包方式安裝
1)解除安裝系統自帶的 mysql和mariadb-lib [root@kevin ~]# /bin/rpm -e $(/bin/rpm -qa | grep mysql|xargs) --nodeps [root@kevin ~]# /bin/rpm -e $(/bin/rpm -qa | grep mariadb|xargs) --nodeps 2)下載mysql5.7.21 rpm安裝包 下載地址:http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.7/ [root@kevin ~]# wget http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.7/mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar [root@kevin ~]# tar -vxf mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar [root@kevin ~]# ll 總用量 1160052 -rw-------. 1 root root 2090 1月 24 02:35 anaconda-ks.cfg -rw-r--r--. 1 root root 593940480 12月 28 21:03 mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar -rw-r--r--. 1 7155 31415 25107316 12月 28 20:53 mysql-community-client-5.7.21-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 278844 12月 28 20:53 mysql-community-common-5.7.21-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 3779988 12月 28 20:53 mysql-community-devel-5.7.21-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 46256768 12月 28 20:53 mysql-community-embedded-5.7.21-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 24078148 12月 28 20:53 mysql-community-embedded-compat-5.7.21-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 128571868 12月 28 20:53 mysql-community-embedded-devel-5.7.21-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 2238596 12月 28 20:53 mysql-community-libs-5.7.21-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 2115904 12月 28 20:54 mysql-community-libs-compat-5.7.21-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 55662616 12月 28 20:54 mysql-community-minimal-debuginfo-5.7.21-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 171890056 12月 28 20:54 mysql-community-server-5.7.21-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 15289580 12月 28 20:54 mysql-community-server-minimal-5.7.21-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 118654584 12月 28 20:54 mysql-community-test-5.7.21-1.el7.x86_64.rpm 依次執行(幾個包有依賴關係,所以執行有先後)下面命令安裝 [root@kevin ~]# rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm --force [root@kevin ~]# rpm -ivh mysql-community-libs-5.7.21-1.el7.x86_64.rpm --force [root@kevin ~]# rpm -ivh mysql-community-client-5.7.21-1.el7.x86_64.rpm --force [root@kevin ~]# rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm --force ============================================================================================================= 可能在安裝mysql-community-server-5.7.21-1.el7.x86_64.rpm的時候會有如下報錯: [root@kevin ~]# rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm --force warning: mysql-community-server-5.7.21-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY error: Failed dependencies: libaio.so.1()(64bit) is needed by mysql-community-server-5.7.21-1.el7.x86_64 libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.21-1.el7.x86_64 libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.21-1.el7.x86_64 net-tools is needed by mysql-community-server-5.7.21-1.el7.x86_64 這個報錯的意思是需要安裝libaio包和net-tools包: 安裝libaio-0.3.107-10.el6.x86_64.rpm [root@kevin ~]# wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm [root@kevin ~]# rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm --force 安裝net-tools [root@kevin ~]# yum install net-tools ============================================================================================================= 使用rpm安裝方式安裝mysql,安裝的路徑如下: 資料庫目錄 /var/lib/mysql/ 配置檔案 /usr/share/mysql(mysql.server命令及配置檔案) /etc/my.cnf 相關命令 /usr/bin(mysqladmin mysqldump等命令) 啟動指令碼 /etc/rc.d/init.d/(啟動指令碼檔案mysql的目錄) 3)資料庫初始化 為了保證資料庫目錄為與檔案的所有者為 mysql 登陸使用者,如果你是以 root 身份執行 mysql 服務,需要執行下面的命令初始化 [root@kevin ~]# mysql_install_db --datadir=/var/lib/mysql //必須指定datadir,執行後會生成~/.mysql_secret密碼檔案 [root@kevin ~]# mysqld --initialize --user=mysql //新版的推薦此方法,執行生會在/var/log/mysqld.log生成隨機密碼。如果是以mysql身份執行,則可以去掉--user選項。 4)更改mysql資料庫目錄的所屬使用者及其所屬組,然後啟動mysql資料庫 [root@kevin ~]# chown mysql:mysql /var/lib/mysql -R [root@kevin ~]# systemctl start mysqld.service //啟動mysql資料庫服務 5)根據第3步中的密碼登入到mysql,更改root使用者的密碼,新版的mysql在第一次登入後更改密碼前是不能執行任何命令的 另外--initialize 選項預設以“安全”模式來初始化,則會為 root 使用者生成一個密碼並將該密碼標記為過期,登陸後你需要設定一個新的密碼, 而使用--initialize-insecure命令則不使用安全模式,則不會為 root 使用者生成一個密碼。 這裡演示使用的--initialize初始化的,會生成一個 root 賬戶密碼,密碼在log檔案裡,如下最後的")1r3gi,hjgQa"即為隨即生成的root密碼 [root@kevin ~]# cat /var/log/mysqld.log ....... 07T04:41:58.420558Z 1 [Note] A temporary password is generated for root@localhost: )1r3gi,hjgQa [root@kevin ~]# mysql -uroot -p')1r3gi,hjgQa' mysql> set password=password('kevin@123'); mysql> flush privileges
三、編譯方式安裝
1)解除安裝系統自帶的 mysql和mariadb-lib [root@kevin ~]# /bin/rpm -e $(/bin/rpm -qa | grep mysql|xargs) --nodeps [root@kevin ~]# /bin/rpm -e $(/bin/rpm -qa | grep mariadb|xargs) --nodeps 2)安裝編譯程式碼需要的包 /usr/bin/yum -y install make gcc-c++ cmake bison-devel ncurses-devel [root@kevin ~]# 3)安裝boost [root@kevin ~]# mkdir -p /usr/local/boost [root@kevin ~]# cd /usr/local/boost [root@kevin boost]# wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz [root@kevin boost]# tar -zvxf boost_1_59_0.tar.gz 4)編譯安裝mysql5.7.21 [root@kevin ~]# /usr/sbin/groupadd mysql [root@kevin ~]# /usr/sbin/useradd -g mysql mysql -M -s /sbin/nologin [root@kevin ~]# cd /usr/local/src [root@kevin src]# wget -c http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.7/mysql-5.7.21.tar.gz [root@kevin src]# /bin/tar -zxvf mysql-5.7.21.tar.gz [root@kevin src]# cd mysql-5.7.21/ [root@kevin mysql-5.7.21]# /usr/bin/cmake -DCMAKE_INSTALL_PREFIX=/data/mysql -DMYSQL_DATADIR=/data/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=/usr/local/boost [root@kevin mysql-5.7.21]# make && make install 5)修改/data/mysql許可權 [root@kevin mysql-5.7.21]# mkdir -p /data/mysql/data [root@kevin mysql-5.7.21]# /bin/chown -R mysql:mysql /data/mysql [root@kevin mysql-5.7.21]# /bin/chown -R mysql:mysql /data/mysql/data 6)執行初始化配置指令碼,建立系統自帶的資料庫和表 [root@kevin mysql-5.7.21]# /data/mysql/bin/mysql_install_db --basedir=/data/mysql --datadir=/data/mysql/data --user=mysql 7)配置my.cnf [root@kevin mysql-5.7.21]# cat /data/mysql/my.cnf [client] port = 3306 socket = /data/mysql/var/mysql.sock [mysqld] port = 3306 socket = /data/mysql/var/mysql.sock basedir = /data/mysql/ datadir = /data/mysql/data pid-file = /data/mysql/data/mysql.pid user = mysql bind-address = 0.0.0.0 server-id = 1 sync_binlog=1 log_bin = mysql-bin skip-name-resolve #skip-networking back_log = 600 max_connections = 3000 max_connect_errors = 3000 ##open_files_limit = 65535 table_open_cache = 512 max_allowed_packet = 16M binlog_cache_size = 16M max_heap_table_size = 16M tmp_table_size = 256M read_buffer_size = 1024M read_rnd_buffer_size = 1024M sort_buffer_size = 1024M join_buffer_size = 1024M key_buffer_size = 8192M thread_cache_size = 8 query_cache_size = 512M query_cache_limit = 1024M ft_min_word_len = 4 binlog_format = mixed expire_logs_days = 30 log_error = /data/mysql/data/mysql-error.log slow_query_log = 1 long_query_time = 1 slow_query_log_file = /data/mysql/data/mysql-slow.log performance_schema = 0 explicit_defaults_for_timestamp ##lower_case_table_names = 1 skip-external-locking default_storage_engine = InnoDB ##default-storage-engine = MyISAM innodb_file_per_table = 1 innodb_open_files = 500 innodb_buffer_pool_size = 40960M innodb_write_io_threads = 1000 innodb_read_io_threads = 1000 innodb_thread_concurrency = 8 innodb_purge_threads = 1 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 4M innodb_log_file_size = 32M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 bulk_insert_buffer_size = 8M #myisam_sort_buffer_size = 8M #myisam_max_sort_file_size = 1G #myisam_repair_threads = 1 interactive_timeout = 28800 wait_timeout = 28800 [mysqldump] quick max_allowed_packet = 16M [myisamchk] key_buffer_size = 8M sort_buffer_size = 8M read_buffer = 4M write_buffer = 4M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES port = 3306 8) 啟動mysql服務 [root@kevin mysql-5.7.21]# cd /data/mysql [root@kevin mysql]# /bin/mkdir var [root@kevin mysql]# /bin/chown -R mysql.mysql var [root@kevin mysql]# cp support-files/mysql.server /etc/init.d/mysql [root@kevin mysql]# /sbin/chkconfig mysql on [root@kevin mysql]# service mysql start 9) 設定環境變數 [root@kevin mysql]# echo "export PATH=$PATH:/data/mysql/bin" >> /etc/profile [root@kevin mysql]# source /etc/profile 10)設定mysql登陸密碼,初始密碼為nextcloud@123 [root@kevin mysql]# /bin/mkdir -p /var/lib/mysql [root@kevin mysql]# ln -s /data/mysql/var/mysql.sock /var/lib/mysql/mysql.sock 11)修改密碼 由於MySQL從5.7開始不允許首次安裝後預設使用空密碼進行登入!並且mysql5.7之後的資料庫裡mysql.user表裡已經沒有password這個欄位了, password欄位改成了authentication_string。 所以修改密碼的命令如下: [root@kevin mysql]# vim /data/mysql/my.cnf ...... [mysqld] ...... skip-grant-tables //先設定無密碼登陸 [root@kevin mysql]# service mysql restart [root@kevin mysql]# mysql -p mysql> update mysql.user set authentication_string=password('kevin@123') where user='root'; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> 然後再將/data/mysql/my.cnf配置檔案中的"skip-grant-tables"去掉,重啟mysql服務,就可以使用上面重置後的新密碼kevin@123登陸了!
===================================================================================================
溫馨提示:
如果是mysql5.7.23版本, 則就不能使用mysql_install_db進行初始化了, 需要使用mysqld --initialize!
[root@lamp-new mysql-5.7.23]# /data/mysql/bin/mysql_install_db --basedir=/data/mysql --datadir=/data/mysql/data --user=mysql 2018-11-22 14:16:02 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize 2018-11-22 14:16:18 [WARNING] The bootstrap log isn't empty: 2018-11-22 14:16:18 [WARNING] 2018-11-22T06:16:02.633498Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead 2018-11-22T06:16:02.645463Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000) 2018-11-22T06:16:02.645476Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000) 可以看到mysql_install_db is deprecated,說不贊同使用mysql_install_db,推薦使用的方法是: Please consider switching to mysqld --initialize ,Please consider using --initialize instead 所以正確的初始方式是使用mysqld --initialize, 而不是之前的mysql_install_db, mysql5.7新特性!!!!! [root@lamp-new mysql]# /data/mysql/bin/mysqld --basedir=/data/mysql --datadir=/data/mysql/data --user=mysql --initialize 2018-11-22T06:25:33.481308Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-11-22T06:25:34.192747Z 0 [Warning] InnoDB: New log files created, LSN=45790 2018-11-22T06:25:34.473292Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2018-11-22T06:25:34.664979Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 6b50ba05-ee1f-11e8-afc3-005056880f83. 2018-11-22T06:25:34.689381Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2018-11-22T06:25:34.690649Z 1 [Note] A temporary password is generated for root@localhost: JR6wA4ezp3&M 注意上面: MySQL 5.7初始化完後會生成一個臨時的密碼,A temporary password is generated for root@localhost: )vyd3aXj8hhC 如果想初始化表空間, 在後面加上 --innodb_data_file_path=ibdata1:1G:autoextend即可。
四、yum安裝MariaDB
[root@kevin ~]# yum -y install mariadb mariadb-server [root@kevin ~]# systemctl start mariadb [root@kevin ~]# systemctl enable mariadb 接下來進行MariaDB的相關簡單配置,設定密碼,會提示先輸入密碼 [root@kevin ~]# mysql_secure_installation 首先是設定密碼,會提示先輸入密碼 Enter current password for root (enter for none):<–初次執行直接回車 設定密碼 Set root password? [Y/n] <– 是否設定root使用者密碼,輸入y並回車或直接回車 New password: <– 設定root使用者的密碼 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@kevin ~]# mysql -p123456 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 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 databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 4 rows in set (0.01 sec) MariaDB [(none)]> 接下來配置MariaDB的字符集: -> 首先是配置檔案/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,在[client]中新增 default-character-set=utf8 -> 然後配置檔案/etc/my.cnf.d/mysql-clients.cnf,在[mysql]中新增 default-character-set=utf8 最後是重啟MariaDB,並登陸MariaDB檢視字符集 [root@test-vm001 my.cnf.d]# systemctl restart mariadb [root@kevin ~]# mysql -p123456 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)]> 為Confluence建立對應的資料庫、使用者名稱和密碼 MariaDB [(none)]> create database confluence default character set utf8 collate utf8_bin; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> grant all on confluence.* to 'confluence'@'%' identified by 'confluencepasswd'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec)