CentOS7 安裝 MariaDB 10.2.4

CentOS7 安裝 MariaDB 10.2.4

CentOS 6 及之前的版本中提供的是 MySQL 的服務器/客戶端安裝包,但 CentOS 7 已使用了 MariaDB 替代了默認的 MySQL。MariaDB數據庫管理系統是MySQL的一個分支,主要由開源社區在維護,採用GPL授權許可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能輕鬆成爲MySQL的代替品。

1、刪除自帶 MySQL/MariaDB

1.1、搜索 MariaDB 現有包

使用rpm -qa | grep mariadb搜索 MariaDB 現有的包。如果存在,使用 rpm -e --nodeps mariadb-* 全部刪除:

[root@master ~]# rpm -qa | grep mariadb
mariadb-server-5.5.52-1.el7.x86_64
mariadb-libs-5.5.52-1.el7.x86_64
[root@localhost ~]# rpm -e mysql-*
錯誤:未安裝軟件包 mysql-* 

1.2、移除 MariaDB 現有包

如果存在,使用 yum remove mysql mysql-server mysql-libs compat-mysql51 全部刪除:

[root@master ~]# yum remove mysql mysql-server mysql-libs compat-mysql51
已加載插件:fastestmirror, langpacks
參數 mysql 沒有匹配
參數 mysql-server 沒有匹配
參數 compat-mysql51 沒有匹配
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 mariadb-libs.x86_64.1.5.5.52-1.el7 將被 刪除
--> 正在處理依賴關係 libmysqlclient.so.18()(64bit),它被軟件包 perl-DBD-MySQL-4.023-5.el7.x86_64 需要
--> 正在處理依賴關係 libmysqlclient.so.18()(64bit),它被軟件包 2:postfix-2.10.1-6.el7.x86_64 需要
--> 正在處理依賴關係 libmysqlclient.so.18()(64bit),它被軟件包 1:qt-mysql-4.8.5-13.el7.x86_64 需要..........

刪除:
  mariadb-libs.x86_64 1:5.5.52-1.el7                                            

作爲依賴被刪除:
  akonadi-mysql.x86_64 0:1.9.2-4.el7     mariadb-server.x86_64 1:5.5.52-1.el7   
  perl-DBD-MySQL.x86_64 0:4.023-5.el7    postfix.x86_64 2:2.10.1-6.el7          
  qt-mysql.x86_64 1:4.8.5-13.el7        

完畢!
[root@master ~]# rpm -qa|grep mariadb
[root@master ~]#

2、MariaDB 安裝

2、Server 和 Client 安裝

[root@master ~]# yum -y install MariaDB-server MariaDB-client
Loaded plugins: fastestmirror, langpacks
(1/7): epel/7/x86_64/updateinfo
	...
(7/7): pgdg95/7/x86_64/primary_db
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
	...
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================
 Package                             Arch               Version
==============================================================================
Installing:
 MariaDB-client                      x86_64             10.2.4-1.el7.centos
 MariaDB-server                      x86_64             10.2.4-1.el7.centos
Installing for dependencies:
 MariaDB-common                      x86_64             10.2.4-1.el7.centos
 MariaDB-compat                      x86_64             	
 ...

Transaction Summary
==============================================================================
Install  2 Packages (+12 Dependent packages)

Total size: 173 M
Total download size: 113 M
Installed size: 731 M
	  ...

Complete!

在這裏插入圖片描述
在這裏插入圖片描述

在這裏插入圖片描述

[root@master ~]# systemctl start mariadb
[root@master ~]# systemctl enable mariadb
[root@master ~]# systemctl restart mariadb
[root@master ~]# systemctl stop mariadb.service

在這裏插入圖片描述

[root@master ~]# mysql -uroot -p123456

在這裏插入圖片描述

[root@master etc]# cat /etc/my.cnf

如果/etc/my.cnf.d 目錄下無server.cnf文件,則直接在/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
    [root@master my.cnf.d]# mysql -uroot -p123456
    MariaDB [(none)]> show variables like "%character%";show variables like "%collation%";

在這裏插入圖片描述
在這裏插入圖片描述

MariaDB [(none)]> create user mariadb@localhost identified by '123456';

MariaDB [(none)]> grant all on *.* to mariadb@localhost identified by '123456';

MariaDB [(none)]> grant all privileges on *.* to mariadb@'%' identified by '123456';

MariaDB [(none)]> grant all privileges on *.* to mariadb@'master' identified by '123456' with grant option;

在這裏插入圖片描述

MariaDB [(none)]> use mysql;

MariaDB [mysql]> select host,user,password from user;


忘記root用戶名和密碼
首先用

 killall -TERM mysqld 

mysqld server 發送kill命令關掉mysqld server(不是 kill -9),必須是UNIX的root用戶或者是所運行的SERVER上的同等用戶,才能執行這個操作

然後

 /usr/bin/mysqld_safe  --skip-grant-tables --skip-networking & 

登錄 : mysql -p或者使用mysql無密碼登錄

use mysql
update user set password=password(“new_pass”) where user=“root”;
flush privileges;

exit;

修改完成之後重啓數據庫,即可用修改好 root 密碼登錄 .


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章