前言
1锉矢、刪除舊版本
2待诅,創(chuàng)建 MariaDB.repo
3恤煞、安裝 install MariaDB
4橘荠、 安裝完成MariaDB膨疏,首先啟動(dòng)MariaDB
5键菱、 設(shè)置開(kāi)機(jī)啟動(dòng)
systemctl 常用命令:
6充坑、 接下來(lái)進(jìn)行MariaDB的相關(guān)簡(jiǎn)單配置
7.測(cè)試登錄?
8熔任、配置mariaDB相關(guān)字符集
1)拆融、文件/etc/my.cnf
2)蠢琳、文件/etc/my.cnf.d/client.cnf
3)、文件/etc/my.cnf.d/mysql-clients.cnf
4)镜豹、全部配置完成傲须,重啟mariadb
5)、之后進(jìn)入MariaDB查看字符集
9趟脂、添加用戶(hù)泰讽、設(shè)置權(quán)限
創(chuàng)建用戶(hù)命令
?10、遠(yuǎn)程訪問(wèn)數(shù)據(jù)庫(kù)
1)昔期、centos6或更早前的版本系統(tǒng)
2)已卸、centos7
前言
mariadb 和mysql就像親兄弟的關(guān)系,各種語(yǔ)法硼一、驅(qū)動(dòng)啥的累澡,在mysql上能上的,在mariadb上基本都可以直接使用般贼。更多的細(xì)節(jié)在此不多說(shuō)永乌。
1、刪除舊版本
centos7下默認(rèn)安裝有mariadb數(shù)據(jù)庫(kù)具伍,但是是舊版本翅雏,在安裝新版本前需要先把舊版本刪除,有些系統(tǒng)還默認(rèn)安裝mysql人芽,也必須刪除望几,否則與mariadb會(huì)產(chǎn)生沖突,如下命令過(guò)程:
rpm -qa | grep mariadb
結(jié)果如下:
用命令yum刪除以上三個(gè):
yum remove mariadb-server-5.5.60-1.el7_5.x86_64
yum remove mariadb-5.5.60-1.el7_5.x86_64
yum remove mariadb-libs-5.5.60-1.el7_5.x86_64
2萤厅,創(chuàng)建 MariaDB.repo
安裝最新版本:https://downloads.mariadb.org/mariadb/repositories/#mirror=shanghai-university&distro=CentOS&distro_release=centos7-amd64--centos7&version=10.3
在目錄下 /etc/yum.repos.d/ 創(chuàng)建文件: MariaDB.repo
并把以下內(nèi)容添加到所建文件中
# MariaDB 10.3 CentOS repository list - created 2018-10-16 15:18 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
以上是官方源橄抹,這里我們用阿里源靴迫,內(nèi)容如下:
[mariadb]
name = MariaDB
baseurl =?http://mirrors.aliyun.com/mariadb/yum/10.3/centos7-amd64/
gpgkey = ?http://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck =?1
3、安裝 install MariaDB
sudo yum install MariaDB-server MariaDB-client
4楼誓、 安裝完成MariaDB玉锌,首先啟動(dòng)MariaDB
systemctl start mariadb
5、 設(shè)置開(kāi)機(jī)啟動(dòng)
systemctl enable mariadb
systemctl 常用命令:
systemctl start mariadb #啟動(dòng)服務(wù)
systemctl enable mariadb #設(shè)置開(kāi)機(jī)啟動(dòng)
systemctl restart mariadb #重新啟動(dòng)
systemctl stop mariadb.service #停止MariaDB
6疟羹、 接下來(lái)進(jìn)行MariaDB的相關(guān)簡(jiǎn)單配置
輸入以下命令:
mysql_secure_installation
先是設(shè)置密碼主守,會(huì)提示先輸入密碼
Enter current password for root (enter for none):<–初次運(yùn)行直接回車(chē)
設(shè)置密碼
Set root password? [Y/n]?<– 是否設(shè)置root用戶(hù)密碼,輸入y并回車(chē)或直接回車(chē)
New password:?<– 設(shè)置root用戶(hù)的密碼
Re-enter new password:?<– 再輸入一次你設(shè)置的密碼
其他配置
Remove anonymous users? [Y/n]?<– 是否刪除匿名用戶(hù)榄融,Y参淫,回車(chē)
Disallow root login remotely? [Y/n]?<–是否禁止root遠(yuǎn)程登錄,N,回車(chē),
Remove test database and access to it? [Y/n]?<– 是否刪除test數(shù)據(jù)庫(kù)愧杯,n,回車(chē)
Reload privilege tables now? [Y/n]?<– 是否重新加載權(quán)限表涎才,回車(chē)
初始化MariaDB完成,接下來(lái)測(cè)試登錄
這里我設(shè)置的密碼:luxxxxxx
7.測(cè)試登錄?
mysql -u root -p
成功登錄后顯示如下:
8力九、配置mariaDB相關(guān)字符集
1)耍铜、文件/etc/my.cnf
vi /etc/my.cnf
添加如下內(nèi)容:
[mysqld]
init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake
2)、文件/etc/my.cnf.d/client.cnf
vi /etc/my.cnf.d/client.cnf
在[client]中添加
default-character-set=utf8
3)跌前、文件/etc/my.cnf.d/mysql-clients.cnf
vi /etc/my.cnf.d/mysql-clients.cnf
在[mysql]中添加
default-character-set=utf8
4)业扒、全部配置完成,重啟mariadb
systemctl restart mariadb
5)程储、之后進(jìn)入MariaDB查看字符集
mysql> show variables like "%character%";show variables like "%collation%";
9、添加用戶(hù)臂寝、設(shè)置權(quán)限
創(chuàng)建用戶(hù)命令
mysql>create user lhy@192.168.1.10 identified by 'luxxxxxx';
或 直接創(chuàng)建用戶(hù)并授權(quán)的命令
mysql>
grant all on *.* to lhy@192.168.1.10 indentified by 'luxxxxxx';
或 授予外網(wǎng)登陸權(quán)限?
mysql>grant all privileges on *.* to username@'%' identified by 'password';
或? 授予權(quán)限并且可以授權(quán)
mysql>grant all privileges on *.* to lhy@'192.168.1.10' identified by 'lu5896848' with grant option;
mysql>flush privileges;
簡(jiǎn)單的用戶(hù)和權(quán)限配置基本就這樣了章鲤。
其中只授予部分權(quán)限把?其中?all?privileges或者all改為select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file其中一部分。
?10咆贬、遠(yuǎn)程訪問(wèn)數(shù)據(jù)庫(kù)
遠(yuǎn)程訪問(wèn)MySQL,需開(kāi)放默認(rèn)端口號(hào)3306败徊,方式有兩種:
1)、centos6或更早前的版本系統(tǒng)
vi /etc/sysconfig/iptables
修改
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
#在里面加入這2行:
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 3306 -j ACCEPT
#改為
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
如果該 iptables 配置文件 不存在,先執(zhí)行yum install iptables-services安裝
執(zhí)行 iptables 重啟生效
service iptables restart
2)掏缎、centos7
執(zhí)行
firewall-cmd --permanent --zone=public --add-port=3306/tcp
firewall-cmd --permanent --zone=public --add-port=3306/udp
這樣就開(kāi)放了相應(yīng)的端口皱蹦。
執(zhí)行
firewall-cmd --reload
最后,如果你是用的國(guó)外服務(wù)器眷蜈,記得還要設(shè)置一個(gè)時(shí)區(qū)?default-time-zone = '+8:00'
另外沪哺,如果外部訪問(wèn)不了,嘗試把防火墻關(guān)閉看一下酌儒。