1.準備Linux環境(系統:CentOS7)
2.準備MySQL安裝套件(版本:8.0.20)
3.安裝方式為: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
注意記住臨時密碼,後面登入時使用,例如:
##6.設定msyql環境變數新增了環境變量,作業系統才能夠自己找到mysql、mysqld_multi等指令的位置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] [Serverpass for temporary for temporary temporgenated temporgenated temporgenated temporgeniated temporgeniated temporgeni n localhost: a8093152e673feb7aba1828c43532094y)qhyh/4E7
2022-04-04T15:15:32.283026Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhostw;
## 在/etc/profile 文件末尾添加 export PATH=/usr/app/mysql/mysql-8.0/bin:$PATH ## 使环境变量生效 source /etc/profile7.啟動與檢視mysql 服務(需指定設定檔)
## 启动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.設定遠端存取密碼cat /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
以上是MySQL8.0.20單機多怎麼部署的詳細內容。更多資訊請關注PHP中文網其他相關文章!