Mysql多实例搭建部署
【部署背景】
公司测试环境需求多个数据库实例,但是只分配一台MySQL机器,所以进行多实例部署。
【部署搭建】
- 创建软件包路径
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
mkdir /data/soft/package /data/server /data/dbdata/65001
- 下载安装包
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
cd /data/soft/package wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
- 查找系统自带的 mysql,并且移除
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
rpm -qa |grep mysql |xargs -I '{}' rpm -e {} --nodeps
- 创建 mysql 实例运行用户
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
useradd mysql
- 解压 mysql 的压缩包到 /data/server 目录
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
tar xf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /data/server/ cd /data/server mv mysql-5.7.30-linux-glibc2.12-x86_64/ mysql_65001
- 创建第一个数据库实例数据目录,服务目录,日志目录等,并且赋予mysql权限
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
mkdir /data/dbdata/65001 -p mkdir /data/server/mysql_65001/etc -p mkdir /data/server/mysql_65001/logs -p mkdir /data/server/mysql_65001/mysql_bin/ -p chown -R mysql:mysql /data/server /data/dbdata
- 初始化,这里要记住初始化密码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
cd /data/server/mysql_65001 bin/mysqld --initialize --user=mysql --basedir=/data/server/mysql_4001 --datadir=/data/dbdata/65001
- 创建了在非加密连接上使用SSL和RSA进行安全传输所需要的SSL证书和key
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
cd /data/server/mysql_65001 bin/mysql_ssl_rsa_setup --datadir=/data/dbdata/65001/
- 更改mysql配置文件my.cnf
- 增加Mysql的错误日志文件
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
touch /data/server/mysql_65001/logs/mysql_65001.err
- 启动MySQL
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
cd /data/server/mysql_65001 chown -R mysql:mysql /data/server /data/dbdata ./bin/mysqld_safe --defaults-file=/data/server/mysql_65001/etc/my.cnf --user=mysql & netstat -anpt |grep 65001
- 更改登录密码,并开启root用户远程访问
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
./bin/mysql -h127.0.0.1 -P65001 -p <初始化的密码> SET PASSWORD FOR 'root'@localhost=PASSWORD('新密码'); update mysql.user set host = '%' where user = 'root'; flush privileges;
- 添加系统路径
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
echo "export PATH=/data/server/mysql_65001/bin:$PATH" >>/etc/profile source /etc/profile
- 第二个以后的实例创建步骤和以上一致即可;服务目录自行更改,比如第二个实例目录如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
/data/server/mysql_65002 /data/dbdata/65002 /data/server/mysql_65002/etc /data/server/mysql_65002/logs /data/server/mysql_65002/mysql_bin/ /data/server/mysql_65002/logs/mysql_65002.err
- 但行好事,
莫问前程 -