0.环境需要
- 1.准备Linux环境(系统:CentOS7)
- 2.准备MySQL安装包(版本:8.0.20)
- 3.安装方式为:msyql解压安装
1.安装步骤
下载地址:https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.20-el7-x86_64.tar.gz
- 2.上传解压缩(我这里的上传为:xhell,当然也可使用其他方式)
mkdir -p /usr/app/mysql
cd /usr/app/mysql
tar -zxvf mysql-8.0.20-el7-x86_64.tar.gz
mv mysql-8.0.20-el7-x86_64 mysql-8.0
- 3.在mysql目录创建创建数据文件存放路径并赋权
mkdir -p /usr/app/mysql/mysql-8.0/{3306,3307,3308}/data
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
groupadd mysql
useradd -g mysql mysql
chown -R mysql:mysql /usr/app/mysql
[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
[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
character_set_server=utf8mb4
init_connect='SET NAMES utf8mb4'
lower_case_table_names=1
explicit_defaults_for_timestamp=true
[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
character_set_server=utf8mb4
init_connect='SET NAMES utf8mb4'
lower_case_table_names=1
explicit_defaults_for_timestamp=true
[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
character_set_server=utf8mb4
init_connect='SET NAMES utf8mb4'
lower_case_table_names=1
explicit_defaults_for_timestamp=true
/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
注意记住临时密码,后面登录时使用,例如:
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<wd
添加了环境变量,操作系统才能够自己找到mysql、mysqld_multi等命令的位置
export PATH=/usr/app/mysql/mysql-8.0/bin:$PATH
source /etc/profile
- 7.启动与查看 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
mysqld_multi --defaults-file=/etc/my.cnf report
启动不成功,查看 mysqld_multi.log 日志或各实例目录下的错误日志 cat /usr/app/mysql/mysql-8.0/mysqld_multi.log cat /usr/app/mysql/mysql-8.0/3306/log/error.log
mysql -uroot -p -S /tmp/mysql_3306.sock
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mysql@123';
use mysql;
update user set host='%' where user='root';
flush privileges;
GRANT ALL ON *.* TO 'root'@'%';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Mysql@123';
flush privileges;
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
然后就可以外部访问了,以上就是我的MySQL8.0单机多实例安装步骤采坑记录。
|