linux下mariadb安裝初始化,字符集設定
Linux下安裝Mariadb,我是使用的centos 7.1系統,在yum源配置好的情況下
yum search mariadb
搜尋結果如下
==================================================================================== N/S matched: mariadb =====================================================================================mariadb-bench.x86_64 : MariaDB benchmark scripts and data
mariadb-devel.i686 : Files for development of MariaDB/MySQL applications
mariadb-devel.x86_64 : Files for development of MariaDB/MySQL applications
mariadb-embedded.i686 : MariaDB as an embeddable library
mariadb-embedded.x86_64 : MariaDB as an embeddable library
mariadb-embedded-devel.i686 : Development files for MariaDB as an embeddable library
mariadb-embedded-devel.x86_64 : Development files for MariaDB as an embeddable library
mariadb-libs.x86_64 : The shared libraries required for MariaDB/MySQL clients
mariadb-libs.i686 : The shared libraries required for MariaDB/MySQL clients
mariadb-server.x86_64 : The MariaDB server and related files
mariadb.x86_64 : A community developed branch of MySQL
mariadb-test.x86_64 : The test suite distributed with MariaD
percona-xtrabackup.x86_64 : Online backup for InnoDB/XtraDB in MySQL, Percona Server and MariaDB
然後安裝mariadb-server.x86_64 mariadb.x86_64這兩個包(一個是服務一個是客戶端,不同的系統名字可能不一樣)
yum install mariadb.x86_64
yum install mariadb-server.x86_64
或者 yum groupinstall -y mariadb mariadb-server
或者直接yum install mariadb會直接裝好(我第一次就是直接使用這個命令裝好的)
裝完後啟動mariadb
systemctl start mariadb
先進一下資料庫試一下,沒問題就是安裝完成
#########################################################################################
接下來就是初始化了
mysql_secure_installation #這是一個快速初始化的命令
首先他會提示輸入root密碼
Enter current password for root (enter for none):
初次安裝時沒有密碼的所以直接回車
然後Change the root password? [Y/n] 修改密碼
Remove anonymous users? [Y/n] 移除匿名使用者,這個一般都要移除
Disallow root login remotely? [Y/n] 不允許root使用者遠端登入,一般是不允許,所以yes
Remove test database and access to it? [Y/n] 刪除test資料庫,這個不是太重要
Reload privilege tables now? [Y/n] 是否重新載入授權表 yes
這樣基本初始化就完成了
###########################################################################################
設定字符集一般建議是在配置檔案中設定,也可以在資料庫中設定,在資料庫中設定的話當服務重啟後就會恢復預設字符集,會出現亂碼現象
配置檔案一般在/etc/my.cnf
vim /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
在[client]下新增 (有些配置檔案沒有[client],是因為包含了 “!includedir /etc/my.cnf.d”這句話,說明其他配置在這個目錄中)
default-character-set=utf8
然後重啟mariadb
登入資料庫檢視字符集是否設定正確 show variables like "%character%";show variables like "%collation%"
這樣就設定成功了
建立資料庫:
CREATE DATABASE `test2` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
匯入sql檔案
Source sql檔案路徑
原文地址:http://te-amo.site/user/article/info/ARTICLE20180210043704870