Home > Database > Mysql Tutorial > How to deploy MySQL8.0.20 on multiple machines

How to deploy MySQL8.0.20 on multiple machines

WBOY
Release: 2023-05-28 21:19:04
forward
1234 people have browsed it

0. Environment requirements

1. Prepare the Linux environment (system: CentOS7)
2. Prepare the MySQL installation package (version: 8.0.20)
3. The installation method is: msyql decompression Installation

1. Installation steps

1. Download and decompress the installed mysql installation package file

2. Upload and decompress (I uploaded it here as: xhell, of course it can also Use other methods)

## 创建mysql目录
mkdir -p /usr/app/mysql
## 移动到目录下
cd /usr/app/mysql
## 使用xhell上传文件到服务器
## 解压后重命名
tar -zxvf mysql-8.0.20-el7-x86_64.tar.gz
mv mysql-8.0.20-el7-x86_64 mysql-8.0
Copy after login

3. Create a data file storage path in the mysql directory and assign it

## 创建各实例数据存放目录
mkdir -p /usr/app/mysql/mysql-8.0/{3306,3307,3308}/data
## 创建各个mysql对应error日志
mkdir -p /usr/app/mysql/mysql-8.0/{3306,3307,3308}/log
touch /usr/app/mysql/mysql-8.0/3306/log/error.log
touch /usr/app/mysql/mysql-8.0/3307/log/error.log
touch /usr/app/mysql/mysql-8.0/3308/log/error.log
## 创建mysql用户组及用户
groupadd mysql
useradd -g mysql mysql
## 目录归属赋权
chown -R mysql:mysql /usr/app/mysql
Copy after login

4. Configure the my.cnf file

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

[client]
default-character-set=utf8mb4

[mysqld]
user=mysql
basedir=/usr/app/mysql/mysql-8.0
lower_case_table_names=1

[mysqld_multi]
mysqld=/usr/app/mysql/mysql-8.0/bin/mysqld_safe
mysqladmin=/usr/app/mysql/mysql-8.0/bin/mysqladmin
log=/usr/app/mysql/mysql-8.0/mysqld_multi.log

# 3306 数据库实例
[mysqld3306]
port=3306
server_id=1
mysqld=mysqld
mysqladmin=mysqladmin
datadir=/usr/app/mysql/mysql-8.0/3306/data
socket=/tmp/mysql_3306.sock
log-error=/usr/app/mysql/mysql-8.0/3306/log/error.log
pid-file=/usr/app/mysql/mysql-8.0/3306/mysql3306.pid

## skip-grant-tables #用于跳过密码登录
character_set_server=utf8mb4
init_connect='SET NAMES utf8mb4'
lower_case_table_names=1
explicit_defaults_for_timestamp=true


# 3307 数据库实例
[mysqld3307]
port=3307
server_id=2
mysqld=mysqld
mysqladmin=mysqladmin
datadir=/usr/app/mysql/mysql-8.0/3307/data
socket=/tmp/mysql_3307.sock
log-error=/usr/app/mysql/mysql-8.0/3307/log/error.log
pid-file=/usr/app/mysql/mysql-8.0/3307/mysql3307.pid
# lc_messages_dir=/usr/local/mysql/share/english

## 默认最大连接数设置
# max_connections=300
character_set_server=utf8mb4
init_connect='SET NAMES utf8mb4'
lower_case_table_names=1
explicit_defaults_for_timestamp=true

# 3308 数据库实例
[mysqld3308]
port=3308
server_id=3
mysqld=mysqld
mysqladmin=mysqladmin
datadir=/usr/app/mysql/mysql-8.0/3308/data
socket=/tmp/mysql_3308.sock
log-error=/usr/app/mysql/mysql-8.0/3308/log/error.log
pid-file=/usr/app/mysql/mysql-8.0/3308/mysql3308.pid
# lc_messages_dir=/usr/local/mysql/share/english

character_set_server=utf8mb4
init_connect='SET NAMES utf8mb4'
lower_case_table_names=1
explicit_defaults_for_timestamp=true
Copy after login

5. Initialize each Instance database

/usr/app/mysql/mysql-8.0/bin/mysqld --defaults-file=/etc/my.cnf --datadir=/usr/app/mysql/mysql-8.0/3306/data/ --initialize
/usr/app/mysql/mysql-8.0/bin/mysqld --defaults-file=/etc/my.cnf --datadir=/usr/app/mysql/mysql-8.0/3307/data/ --initialize
/usr/app/mysql/mysql-8.0/bin/mysqld --defaults-file=/etc/my.cnf --datadir=/usr/app/mysql/mysql-8.0/3308/data/ --initialize
Copy after login

Remember the temporary password, which will be used when logging in later, for example:

2022-04-04T15:12:39.011998Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: sJH):ayhH5cW
2022-04-04T15:14:24.214337Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@ localhost: <>y)qhyh/4E7
2022-04-04T15:15:32.283026Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: s7qrjzwqI

6. Set the msyql environment variable

After adding the environment variable, the operating system can find the location of mysql, mysqld_multi and other commands by itself

## 在/etc/profile 文件末尾添加
export PATH=/usr/app/mysql/mysql-8.0/bin:$PATH

## 使环境变量生效
source /etc/profile
Copy after login

7. Start and view mysql service (configuration file needs to be specified)

## 启动mysql
mysqld_multi --defaults-file=/etc/my.cnf start 3306
mysqld_multi --defaults-file=/etc/my.cnf start 3307
mysqld_multi --defaults-file=/etc/my.cnf start 3308

## 查看mysql服务
mysqld_multi --defaults-file=/etc/my.cnf report
Copy after login

Failed to start, check the mysqld_multi.log log or the error log in each instance directory

cat /usr/app/mysql/mysql -8.0/mysqld_multi.log
cat /usr/app/mysql/mysql-8.0/3306/log/error.log

8. Set the remote access password

## 服务器登录 (注意:另外两个实例同样如此。)
mysql -uroot -p -S /tmp/mysql_3306.sock
## 输入上面初始化数据库时的临时密码

## 设置本地访问密码,例如:Mysql@123,注意密码为高安保等级(例如大小写和特殊字符的组合),不然无法使用其他操作
ALTER USER &#39;root&#39;@&#39;localhost&#39; IDENTIFIED BY &#39;Mysql@123&#39;;
## 进入mysql数据
use mysql;
## 更新root信息
update user set host=&#39;%&#39; where user=&#39;root&#39;;
## 刷新
flush privileges;
# 授权root用户可以远程登陆
GRANT ALL ON *.* TO &#39;root&#39;@&#39;%&#39;;
## 远程连接设置
ALTER USER &#39;root&#39;@&#39;%&#39; IDENTIFIED WITH mysql_native_password BY &#39;Mysql@123&#39;;
## 刷新
flush privileges;
Copy after login

9. Open the access port in the firewall (get to close the firewall)

## 开放防火墙端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=3307/tcp --permanent
firewall-cmd --zone=public --add-port=3308/tcp --permanent

## 查看开放端口
firewall-cmd --list-port

## 配置生效
firewall-cmd --reload
Copy after login

The above is the detailed content of How to deploy MySQL8.0.20 on multiple machines. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template