centos7.6下安装mariadb10.6.8

centos7.6下安装mariadb10.6.8

默认yum安装的版本信息如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@VM-12-3-centos software]# yum info mariadb  
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Packages
Name : mariadb
Arch : x86_64
Epoch : 1
Version : 5.5.68
Release : 1.el7
Size : 8.8 M
Repo : os/7/x86_64
Summary : A community developed branch of MySQL
URL : http://mariadb.org
License : GPLv2 with exceptions and LGPLv2 and BSD
Description : MariaDB is a community developed branch of MySQL.
: MariaDB is a multi-user, multi-threaded SQL database server.
: It is a client/server implementation consisting of a server daemon (mysqld)
: and many different client programs and libraries. The base package
: contains the standard MariaDB/MySQL client programs and generic MySQL files.

所以此处采用添加yum源安装Mariadb

1
2
3
4
5
6
7
8
9
10
# 编辑创建mariadb.repo仓库文件
vi /etc/yum.repos.d/MariaDB.repo

# 添加如下内容
[mariadb]
name = MariaDB
# URL可替换为想用的版本的URL
baseurl = http://yum.mariadb.org/10.6.8/centos7-amd64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

版本URL可在此处找:http://yum.mariadb.org

重新构建缓存:

1
2
yum clean all
yum makecache //此步骤是用刚才所编辑 MariaDB.repo 源的关键

卸载旧版

1
2
3
4
5
6
systemctl stop mariadb // 或者直接ps找出来kill掉
yum remove mariadb-server mariadb mariadb-libs
yum clean all
找出并删除残留目录。
find / -name mariadb
find / -name mysql

安装新的数据库

1
yum install MariaDB-server

启动并查看状态

1
2
systemctl start mariadb
systemctl status mariadb

查看MariaDB数据当前存储位置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@VM-12-3-centos software]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.6.8-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select @@datadir;
+-----------------+
| @@datadir |
+-----------------+
| /var/lib/mysql/ |
+-----------------+
1 row in set (0.000 sec)

MariaDB [(none)]>

退出,编辑vi /etc/my.cnf

1
2
3
4
5
6
7
8
9
10
11
#
# This group is read both by the client and the server
# use it for options that affect everything
#
[client-server]
port=3306
socket = /var/lib/mysql/mysql.sock
#
# include *.cnf from the config directory
#
!includedir /etc/my.cnf.d

编辑/etc/my.cnf.d/server.cnf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# See the examples of server my.cnf files in /usr/share/mysql/
#

# this is read by the standalone daemon and embedded servers
[server]

# this is only for the mysqld standalone daemon
[mysqld]
datadir =/var/lib/mysql
socket = /var/lib/mysql/mysql.sock
#
# * Galera-related settings
#
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
bind-address=0.0.0.0

重新启动服务:

1
systemctl start mariadb

设置密码

查看当前认证状态并修改

1
2
3
4
5
6
7
8
9
10
11
12
MariaDB [(none)]> select user,host, plugin from mysql.user;
+-------------+----------------+-----------------------+
| User | Host | plugin |
+-------------+----------------+-----------------------+
| mariadb.sys | localhost | mysql_native_password |
| root | localhost | mysql_native_password |
| mysql | localhost | mysql_native_password |
| | localhost | |
| | vm-12-3-centos | |
| root | % | mysql_native_password |
+-------------+----------------+-----------------------+
6 rows in set (0.001 sec)

重设密码

1
2
3
ALTER USER `root`@`localhost` IDENTIFIED BY 'yourpassword';

ALTER USER `root`@`%` IDENTIFIED BY 'yourpassword';

记得把3306端口的外网访问权限开了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 查看白名单列表
firewall-cmd --zone=public --list-ports
#此处无3306/tcp

# 添加白名单端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent

# 重启防火墙
firewall-cmd --reload

# 查看白名单列表
firewall-cmd --zone=public --list-ports
#表示3306端口已加入白名单
3306/tcp
# 查看防火墙状态,是否是running
firewall-cmd --state

# 重新载入配置,比如添加规则之后,需要执行此命令
firewall-cmd --reload

# 列出支持的zone
firewall-cmd --get-zones

# 列出支持的服务,在列表中的服务是放行的
firewall-cmd --get-services

# 查看已开放的端口
firewall-cmd --zone=public --list-ports

# 永久添加80端口
firewall-cmd --add-port=3306/tcp --permanent

# 永久添加80端口
firewall-cmd --remove-port=3306/tcp --permanent

# 作用域
--zone

# 添加端口
--add-port=3306/tcp

# 永久生效,没有此参数重启后失效
--permanent

在mysql.user视图中添加root@%用户域

1
GRANT ALL PRIVILEGES ON *.* TO `root`@`%` IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;

MariaDB 10.6.8中(包括之前几个版本,至少是10.4.12之后的版本),user 已经不是 mysql 数据库下的表,而是一个视图,故无法直接修改。

如果觉得写的还行,赞助瓶脉动~
0%