欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

MySQL多实例应用

程序员文章站 2022-03-20 23:30:51
1.下载、上传、解压、软连接(1.)下载官网地址:https://dev.mysql.com/downloads/ (下载速度很慢)国内镜像:http://mirrors.sohu.com/mysql/http://mirrors.163.com/mysql/Downloads/(2.)上传、解压cd /data/app/tar xf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz tar xf mysql-5.7.12-linux-gl...

1.下载、上传、解压、软连接

(1.)下载
	官网地址:https://dev.mysql.com/downloads/ (下载速度很慢)
	国内镜像:http://mirrors.sohu.com/mysql/
			http://mirrors.163.com/mysql/Downloads/
(2.)上传、解压
	cd /data/app/
	tar xf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz 
	tar xf mysql-5.7.12-linux-glibc2.12-x86_64.tar.xz
	tar xf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
(3.)创建软连接
	ln -s mysql-5.6.46-linux-glibc2.12-x86_64 mysql56
	ln -s mysql-5.7.12-linux-glibc2.12-x86_64 mysql57
	ln -s mysql-8.0.18-linux-glibc2.12-x86_64 mysql80

2.设置变量环境

vim /etc/profile 
#添加最后一行
export PATH=/data/app/mysql/bin:$PATH 

#生效配置:
source /etc/profile

3.创建目录

mkdir -p /data/331{6..8}/data  /data/331{6..8}/logs

4.准备配置文件

(1.)3316
	cat >/data/3316/my.cnf <<EOF
	[mysqld] 
	user=mysql 
	basedir=/data/app/mysql56
	datadir=/data/3316/data 
	server_id=16
	port=3316
	log_bin=/data/3316/logs/mysql-bin
	socket=/tmp/mysql3316.sock
	EOF

(2.)3317
	cat >/data/3317/my.cnf <<EOF
	[mysqld] 
	user=mysql 
	basedir=/data/app/mysql57
	datadir=/data/3317/data 
	server_id=17
	port=3317
	log_bin=/data/3317/logs/mysql-bin
	socket=/tmp/mysql3317.sock
	EOF


(3.)3318
	cat >/data/3318/my.cnf <<EOF
	[mysqld] 
	user=mysql 
	basedir=/data/app/mysql80
	datadir=/data/3318/data 
	server_id=18
	port=3318
	log_bin=/data/3318/logs/mysql-bin
	socket=/tmp/mysql3318.sock
	EOF

5.授权

chown -R mysql. /data/*

6.初始化数据

/data/app/mysql56/scripts/mysql_install_db  --user=mysql --basedir=/data/app/mysql56 --datadir=/data/3316/data
/data/app/mysql57/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/app/mysql57 --datadir=/data/3317/data
/data/app/mysql80/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/app/mysql80 --datadir=/data/3318/data

7.配置多实例systemd(方便启动)

(1.)3316
	cat > /etc/systemd/system/mysqld3316.service  <<EOF
	[Unit]
	Description=MySQL Server
	Documentation=man:mysqld(8)
	Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
	After=network.target
	After=syslog.target
	[Install]
	WantedBy=multi-user.target
	[Service]
	User=mysql
	Group=mysql
	ExecStart=/data/app/mysql56/bin/mysqld --defaults-file=/data/3316/my.cnf
	LimitNOFILE = 5000
	EOF


(2.)3317
	cat > /etc/systemd/system/mysqld3308.service  <<EOF
	[Unit]
	Description=MySQL Server
	Documentation=man:mysqld(8)
	Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
	After=network.target
	After=syslog.target
	[Install]
	WantedBy=multi-user.target
	[Service]
	User=mysql
	Group=mysql
	ExecStart=/data/app/mysql57/bin/mysqld --defaults-file=/data/3317/my.cnf
	LimitNOFILE = 5000
	EOF



(3.)3318
	cat > /etc/systemd/system/mysqld3309.service  <<EOF
	[Unit]
	Description=MySQL Server
	Documentation=man:mysqld(8)
	Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
	After=network.target
	After=syslog.target
	[Install]
	WantedBy=multi-user.target
	[Service]
	User=mysql
	Group=mysql
	ExecStart=/data/app/mysql80/bin/mysqld --defaults-file=/data/3318/my.cnf
	LimitNOFILE = 5000
	EOF

8.启动

pkill mysqld (结束之前启动的所有MySQL进程)
systemctl start mysqld3316
systemctl start mysqld3317
systemctl start mysqld3318

9.连接测试一下

/data/app/mysql56/bin/mysql -S /tmp/mysql3316.sock
/data/app/mysql57/bin/mysql -S /tmp/mysql3317.sock
/data/app/mysql80/bin/mysql -S /tmp/mysql3318.sock

本文地址:https://blog.csdn.net/yengboy/article/details/107437697