MySQL-----多实例配置
1.1 MySQL实例---多实例配置
1.1.1 多实例概述
多套后台进程+线程+内存结构
多个端口,多个配置文件,多个日志文件,多个socket,多个server_id
多套数据
##PS:安装多实例前,首先确保MySQL数据库已安装,mysql安装参考:https://blog.51cto.com/zhuzhiwei/2140683
1.1.2 准备多套配置文件
mkdir -p /data/330{7..9} #<=====创建多个目录
================第一个实例===================
vim /data/3307/my.cnf
[mysqld]
basedir=/application/mysql
datadir=/data/3307/data
socket=/data/3307/mysql.sock
log-error=/data/3307/mysql.log
log-bin=/data/3307/mysql-bin
server-id=7
port=3307
[client]
socket=/data/3307/mysql.sock
================第二个实例===================
vim /data/3308/my.cnf
[mysqld]
basedir=/application/mysql
datadir=/data/3308/data
socket=/data/3308/mysql.sock
log-error=/data/3308/mysql.log
log-bin=/data/3308/mysql-bin
server-id=8
port=3308
[client]
socket=/data/3308/mysql.sock
================第三个实例===================
vim /data/3309/my.cnf
[mysqld]
basedir=/application/mysql
datadir=/data/3309/data
socket=/data/3309/mysql.sock
log-error=/data/3309/mysql.log
log-bin=/data/3309/mysql-bin
server-id=9
port=3309
[client]
socket=/data/3309/mysql.sock
=========================================
chown -R mysql.mysql /data/330* #<======将3个目录授权给mysql用户
1.1.3 初始化多套数据
/application/mysql/scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/data/3307/data
=================================================================================
/application/mysql/scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/data/3308/data
=================================================================================
/application/mysql/scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/data/3309/data
=================================================================================
1.1.4 启动多个实例
mysqld_safe --defaults-file=/data/3307/my.cnf &
====================================================================
mysqld_safe --defaults-file=/data/3308/my.cnf &
====================================================================
mysqld_safe --defaults-file=/data/3309/my.cnf &
====================================================================
1.1.5 启动失败处理
touch /data/3309/mysql.log
touch /data/3308/mysql.log
touch /data/3307/mysql.log
chown -R mysql.mysql /data/330*
再次启动多个实例即可。
===============进入实例===============================
mysql -s /data/3307/mysql.sock #首次进入无密码
mysql -s /data/3308/mysql.sock
mysql -s /data/3309/mysql.sock