0
点赞
收藏
分享

微信扫一扫

CentOS8.4二进制安装mariadb-10.7.3数据库

CentOS8.4二进制安装mariadb-10.7.3数据库

内容:下载最新mariadb-10.7.3的稳定版本二进制文件mariadb-10.7.3-linux-systemd-x86_64.tar.gz,在CentOS8.4上完成安装,这个包无my.cnf配置文件,需要自己编写。

1. 主机环境及安装包准备

官网下载地址:https://mariadb.org/download/
CentOS8.4二进制安装mariadb-10.7.3数据库_数据库

# 修改主机名  退出再登录 确保前缀变成新主机名
[root@CentOS84 ]#hostnamectl set-hostname MarriaDB-IP48

# 时钟同步
[root@MarriaDB-IP48 ]#systemctl enable --now chronyd.service
[root@MarriaDB-IP48 ]#

# 查看主机监听的端口,确保没有软件安装冲突
[root@MarriaDB-IP48 ]#ss -tlnp
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 32 192.168.122.1:53 0.0.0.0:* users:(("dnsmasq",pid=1755,fd=6))
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=978,fd=4))
LISTEN 0 5 127.0.0.1:631 0.0.0.0:* users:(("cupsd",pid=973,fd=9))
LISTEN 0 80 0.0.0.0:3306 0.0.0.0:* users:(("mariadbd",pid=1059,fd=23))
LISTEN 0 128 0.0.0.0:111 0.0.0.0:* users:(("rpcbind",pid=867,fd=4),("systemd",pid=1,fd=31))
LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=978,fd=6))
LISTEN 0 5 [::1]:631 [::]:* users:(("cupsd",pid=973,fd=8))
LISTEN 0 80 [::]:3306 [::]:* users:(("mariadbd",pid=1059,fd=24))
LISTEN 0 128 [::]:111 [::]:* users:(("rpcbind",pid=867,fd=6),("systemd",pid=1,fd=36))
[root@MarriaDB-IP48 ]#

[root@MarriaDB-IP48 ]#cd /data/
[root@MarriaDB-IP48 ]#wget https://tw1.mirror.blendbyte.net/mariadb/mariadb-10.7.3/bintar-linux-systemd-x86_64/mariadb-10.7.3-linux-systemd-x86_64.tar.gz
--2022-03-05 11:26:03-- https://tw1.mirror.blendbyte.net/mariadb/mariadb-10.7.3/bintar-linux-systemd-x86_64/mariadb-10.7.3-linux-systemd-x86_64.tar.gz
Resolving tw1.mirror.blendbyte.net (tw1.mirror.blendbyte.net)... 125.228.189.120
Connecting to tw1.mirror.blendbyte.net (tw1.mirror.blendbyte.net)|125.228.189.120|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 346120004 (330M) [application/octet-stream]
Saving to: ‘mariadb-10.7.3-linux-systemd-x86_64.tar.gz’

mariadb-10.7.3-linux-systemd-x 100%[==================================================>] 330.08M 8.85MB/s in 38s

2022-03-05 11:26:42 (8.63 MB/s) - ‘mariadb-10.7.3-linux-systemd-x86_64.tar.gz’ saved [346120004/346120004]

[root@MarriaDB-IP48 ]#ll
total 338020
-rw-------. 1 root root 1412 Nov 17 20:23 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Nov 17 21:18 Desktop
drwxr-xr-x. 2 root root 6 Nov 17 21:18 Documents
drwxr-xr-x. 2 root root 6 Nov 17 21:18 Downloads
-rw-r--r--. 1 root root 1578 Nov 17 20:56 initial-setup-ks.cfg
-rw-r--r-- 1 root root 346120004 Feb 12 07:48 mariadb-10.7.3-linux-systemd-x86_64.tar.gz
drwxr-xr-x. 2 root root 6 Nov 17 21:18 Music
drwxr-xr-x. 2 root root 6 Nov 17 21:18 Pictures
-rw-r--r-- 1 root root 600 Dec 28 00:43 ping_while.sh
drwxr-xr-x. 2 root root 6 Nov 17 21:18 Public
drwxr-xr-x. 2 root root 6 Nov 17 21:18 Templates
drwxr-xr-x. 2 root root 6 Nov 17 21:18 Videos

2. MariaDB的安装和配置

# 查询是否有mysql账号,没有就创建
[root@MarriaDB-IP48 ]#getent passwd mysql

# 创建数据库账号 mysql 组 mysql 非主机登录
[root@MarriaDB-IP48 ]#useradd -r -s /sbin/nologin mysql

# 解压最新的mariadb安装包
[root@MarriaDB-IP48 ]#tar xvf mariadb-10.7.3-linux-systemd-x86_64.tar.gz -C /usr/local > /dev/nul

[root@MarriaDB-IP48 ]#ll /usr/local
drwxrwxr-x 11 summer summer 245 Feb 12 07:47 mariadb-10.7.3-linux-systemd-x86_64
[root@MarriaDB-IP48 ]#

# 进入目录并创建软链接
[root@MarriaDB-IP48 ]#cd /usr/local
[root@MarriaDB-IP48 ]#ln -sv mariadb-10.7.3-linux-systemd-x86_64 mysql
'mysql' -> 'mariadb-10.7.3-linux-systemd-x86_64'

# 查看mysql目录下的文件权属,并修改
[root@MarriaDB-IP48 ]#cd mysql
[root@MarriaDB-IP48 ]#ll
total 164
drwxr-xr-x 2 summer summer 4096 Jan 19 01:31 bin
-rw-r--r-- 1 summer summer 17987 Feb 11 04:33 COPYING
-rw-r--r-- 1 summer summer 2093 Feb 11 04:33 CREDITS
drwxrwxr-x 3 summer summer 19 Feb 11 05:11 include
-rw-r--r-- 1 summer summer 8782 Feb 11 04:33 INSTALL-BINARY
drwxr-xr-x 5 summer summer 293 Jan 19 01:31 lib
drwxrwxr-x 5 summer summer 42 Feb 11 05:12 man
drwxrwxr-x 9 summer summer 4096 Feb 11 05:12 mysql-test
-rw-r--r-- 1 summer summer 2697 Feb 11 04:33 README.md
-rw-r--r-- 1 summer summer 19520 Feb 11 04:33 README-wsrep
drwxrwxr-x 2 summer summer 56 Feb 11 05:12 scripts
drwxrwxr-x 31 summer summer 4096 Feb 11 05:12 share
drwxrwxr-x 4 summer summer 4096 Feb 11 05:12 sql-bench
drwxrwxr-x 4 summer summer 180 Feb 11 05:12 support-files
-rw-r--r-- 1 summer summer 86263 Feb 11 04:33 THIRDPARTY

[root@MarriaDB-IP48 ]#chown -R root.root ./*
#上面的命令等同于 chown -R root:root /usr/local/mysql/

# 权属修改的确认
[root@MarriaDB-IP48 ]#ll
total 164
drwxr-xr-x 2 root root 4096 Jan 19 01:31 bin
-rw-r--r-- 1 root root 17987 Feb 11 04:33 COPYING
-rw-r--r-- 1 root root 2093 Feb 11 04:33 CREDITS
drwxrwxr-x 3 root root 19 Feb 11 05:11 include
-rw-r--r-- 1 root root 8782 Feb 11 04:33 INSTALL-BINARY
drwxr-xr-x 5 root root 293 Jan 19 01:31 lib
drwxrwxr-x 5 root root 42 Feb 11 05:12 man
drwxrwxr-x 9 root root 4096 Feb 11 05:12 mysql-test
-rw-r--r-- 1 root root 2697 Feb 11 04:33 README.md
-rw-r--r-- 1 root root 19520 Feb 11 04:33 README-wsrep
drwxrwxr-x 2 root root 56 Feb 11 05:12 scripts
drwxrwxr-x 31 root root 4096 Feb 11 05:12 share
drwxrwxr-x 4 root root 4096 Feb 11 05:12 sql-bench
drwxrwxr-x 4 root root 180 Feb 11 05:12 support-files
-rw-r--r-- 1 root root 86263 Feb 11 04:33 THIRDPARTY

# 创建数据库存放数据的目录,并授权mysql.mysql
[root@MarriaDB-IP48 ]#mkdir /data/mysql -p
[root@MarriaDB-IP48 ]#chown -R mysql.mysql /data/mysql

# 创建数据库配置文件目录,并编写配置文件 说明:本例的my.cnf属于极小化配置,需要根据生产需要做细化配置
[root@MarriaDB-IP48 ]#mkdir /etc/mysql

[root@MarriaDB-IP48 ]#vim /etc/mysql/my.cnf
[root@MarriaDB-IP48 ]#cat /etc/mysql/my.cnf
[mysqld]
server-id=1
log-bin
datadir=/data/mysql
socket=/data/mysql/mysql.sock
skip_name_resolve = on

log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid

[client]
port=3306
socket=/data/mysql/mysql.sock
[root@MarriaDB-IP48 ]#

## 进入数据库程序文件目录,安装依赖包,初始化安装数据库
[root@MarriaDB-IP48 ]#cd /usr/local/mysql
# 安装依赖包
[root@MarriaDB-IP48 ]#yum -y install libaio
# 初始化安装数据库
[root@MarriaDB-IP48 ]#./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
Installing MariaDB/MySQL system tables in '/data/mysql' ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system


Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql@localhost, it has no password either, but
you need to be the system 'mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo

See the MariaDB Knowledgebase at https://mariadb.com/kb

You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='/data/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd './mysql-test' ; perl mysql-test-run.pl

Please report any problems at https://mariadb.org/jira

The latest information about MariaDB is available at https://mariadb.org/.

Consider joining MariaDBs strong and vibrant community:
https://mariadb.org/get-involved/

# 准备数据库的服务文件
[root@MarriaDB-IP48 ]#cp support-files/systemd/mariadb.service /usr/lib/systemd/system
[root@MarriaDB-IP48 ]#ll
drwxrwxr-x 4 root root 180 Feb 11 05:12 support-files

# 个性化数据库,定义专用的日志等目录,并授权
[root@MarriaDB-IP48 ]#mkdir /var/log/mariadb
[root@MarriaDB-IP48 ]#mkdir /var/run/mariadb

[root@MarriaDB-IP48 ]#chown mysql:mysql /var/log/mariadb
[root@MarriaDB-IP48 ]#chown mysql:mysql /var/run/mariadb

# 设置PATH变量并使之立刻生效
[root@MarriaDB-IP48 ]#echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@MarriaDB-IP48 ]#. /etc/profile.d/mysql.sh

# 启动服务,并设定为开机自动启动
[root@MarriaDB-IP48 ]#systemctl enable --now mariadb
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.

3. 验证数据库

# 查看监听
[root@MarriaDB-IP48 ]#ss -tln
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 80 0.0.0.0:3306 0.0.0.0:*
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
LISTEN 0 80 [::]:3306 [::]:*
LISTEN 0 128 [::]:111 [::]:*

# 进入数据库
[root@MarriaDB-IP48 ]#mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.7.3-MariaDB-log 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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.001 sec)

# 创建库
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> create database discuz;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> grant all on wordpress.* to wordpress@'192.168.250.%' identified by "wppass";
Query OK, 0 rows affected (0.002 sec)

MariaDB [(none)]> grant all on discuz.* to discuz@'192.168.250.%' identified by 'dispass';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| discuz |
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
| wordpress |
+--------------------+
7 rows in set (0.001 sec)

MariaDB [(none)]> show status \G;

MariaDB [(none)]> quit
Bye

[root@MarriaDB-IP48 ]#
举报

相关推荐

0 条评论