1 Sediakan persekitaran Linux (sistem: CentOS7)
2. Sediakan pakej pemasangan MySQL (versi: 8.0.20)
3 : Pemasangan penyahmampatan msyql
## 创建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
## 创建各实例数据存放目录 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
# 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
/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 [Nota] [MY-010454] [Pelayan] Kata laluan sementara dijana untuk root@localhost: sJH):ayhH5cW6. Tetapkan pembolehubah persekitaran msyqlTambahkan pembolehubah persekitaran supaya sistem pengendalian dapat mencari lokasi mysql, mysqld_multi dan arahan lain dengan sendirinya2022-04-04T15:14:24.214337Z 6 [Nota] 010454] [Pelayan] Kata laluan sementara dijana untuk root@ localhost: <>y)qhyh/4E7
2022-04-04T15:15:32.283026Z 6 [Nota] [MY-010454] [Pelayan] A kata laluan sementara dijana untuk root@localhost: s7qrjzwqI
## 在/etc/profile 文件末尾添加 export PATH=/usr/app/mysql/mysql-8.0/bin:$PATH ## 使环境变量生效 source /etc/profile
## 启动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
cat /usr/app/mysql/mysql -8.0/mysqld_multi.log8. Tetapkan kata laluan akses jauhcat /usr/app/mysql/mysql-8.0/3306/log/error.log
## 服务器登录 (注意:另外两个实例同样如此。) mysql -uroot -p -S /tmp/mysql_3306.sock ## 输入上面初始化数据库时的临时密码 ## 设置本地访问密码,例如:Mysql@123,注意密码为高安保等级(例如大小写和特殊字符的组合),不然无法使用其他操作 ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mysql@123'; ## 进入mysql数据 use mysql; ## 更新root信息 update user set host='%' where user='root'; ## 刷新 flush privileges; # 授权root用户可以远程登陆 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
Atas ialah kandungan terperinci Bagaimana untuk menggunakan MySQL8.0.20 pada berbilang mesin. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!