Linux下使用yum安裝MariaDB

版本:centos7mysql

Linux下安裝MariaDB官方文檔參見:https://mariadb.com/kb/zh-cn/installing-mariadb-with-yum/sql

1.建立MariaDB.repo文件數據庫

vi /etc/yum.repos.d/MariaDB.repo

插入如下內容:centos

 

# MariaDB 10.1 CentOS repository list - created 2016-12-01 03:36 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

系統及版本選擇:https://downloads.mariadb.org/mariadb/repositories/#mirror=tunaide

2.運行安裝命令安裝MariaDBurl

 yum -y install MariaDB-server MariaDB-client

首先下載安裝包,而後進行自動安裝,安裝成功以後啓動MariaDB服務。centos7

systemctl start mariadb #啓動服務
systemctl enable mariadb #設置開機啓動
systemctl restart mariadb #從新啓動
systemctl stop mariadb.service #中止MariaDB

3.登陸到數據庫spa

  用mysql -uroot命令登陸到MariaDB,此時root帳戶的密碼爲空。3d

4.進行MariaDB的相關簡單配置rest

  使用mysql_secure_installation命令進行配置。

  

  回車設置root帳戶的密碼

  

  輸入兩次密碼

  

  其餘配置:是否刪除匿名用戶、是否容許遠程登陸、 是否刪除test數據庫、是否從新加載權限表若是都選是,直接回車。

  

5.配置MariaDB的字符集

  查看/etc/my.cnf文件內容,其中包含一句!includedir /etc/my.cnf.d 說明在該配置文件中引入/etc/my.cnf.d 目錄下的配置文件。

  1)使用vi server.cnf命令編輯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 目錄下無server.cnf文件,則直接在/etc/my.cnf文件的[mysqld]標籤下添加以上內容。

  2)vi  client.cnf命令編輯/etc/my.cnf.d/client.cnf文件,在[client]標籤下添加 

default-character-set=utf8

  3)用vi  mysql-clients.cnf命令編輯/etc/my.cnf.d/mysql-clients.cnf文件,在[mysql]標籤下添加 

 

default-character-set=utf8

 

配置完成後 systemctl restart mariadb 重啓服務。

進入到數據庫查看字符設置。

show variables like "%character%"; show variables like "%collation%";

 

6.添加用戶,設置權限

  建立用戶命令:

create user username@localhost identified by 'password';

 

  授予外網登錄權限:

 

 

grant all privileges on *.* to username@'%' identified by 'password';

 

使用新建立的用戶鏈接下數據庫OK!

相關文章
相關標籤/搜索