mysql多实例
Posted krystal_LA
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql多实例相关的知识,希望对你有一定的参考价值。
https://blog.csdn.net/robinson_0612/article/details/40339167
https://www.cnblogs.com/longren/p/11168317.html
step1:卸载所有与mysql,mariadb相关的东西
卸载mysql
# rpm -qa | grep mysql
yum -y remove mysql-community-common-5.7.29-1.el7.x86_64
yum -y remove mysql-community-client-5.7.29-1.el7.x86_64
yum -y remove mysql-community-libs-5.7.29-1.el7.x86_64
yum -y remove mysql-community-server-5.7.29-1.el7.x86_64
卸载MariaDB
# rpm -qa | grep mariadb
将它们统统强制性卸载掉:
# rpm -e --nodeps mariadb-libs-5.5.35-3.el7.x86_64
# rpm -e --nodeps mariadb-5.5.35-3.el7.x86_64
# rpm -e --nodeps mariadb-server-5.5.35-3.el7.x86_64
#yum -y remove mariadb*
step2:安装依赖包
#yum -y install make gcc-c++ gcc cmake bison-devel ncurses-devel libaio libaio-devel autoconf
step3:创建mysql用户
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
tar -xvf mysql-5.6.32-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
mv mysql-5.6.36-linux-glibc2.5-x86_64/ mysql
vim /etc/bashrc
export PATH=/usr/local/mysql/bin:$PATH
source /etc/bashrc
port分开:默认3306
socket分开:默认(/var/lib/mysql/mysql.sock)
mysqld服务运行时,产生socket文件,客户端访问数据库时,与socket文件建立连接
日志分开:默认(/var/log/mysqld.log)
数据目录分开:默认(/var/lib/mysql)
pid文件分开:默认(/var/run/mysqld/mysqld.pid)
创建多实例:
step1:全手写/etc/my.cnf配置文件
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe //指定进程文件路径
mysqladmin = /usr/local/mysql/bin/mysqladmin //指定管理命令路径
user = admin //此帐户用于多实例关闭时使用,需要在每个实例上创建并授权
password = 123456
[mysqld3306]
log-bin=/data/3306/mysql-bin
server_id=6
basedir=/usr/local/mysql
datadir=/data/3306
port=3306
socket=/data/3306/mysql.sock
log-error=/data/3306/mysqld.err
pid-file=/data/3306/mysqld.pid
user=mysql
[mysqld3307]
log-bin=/data/3307/mysql-bin
server_id=7
basedir=/usr/local/mysql
datadir=/data/3307
port=3307
socket=/data/3307/mysql.sock
log-error=/data/3307/mysqld.err
pid-file=/data/3307/mysqld.pid
user=mysql
step2:创建相应的目录
mkdir -p /data/{3306,3307}
step3:初始化数据目录
cd /usr/local/mysql/scripts/
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3307
step4:更改权限
chown -R mysql.mysql /data
step5:启动实例
/usr/local/mysql/bin/mysqld_multi start 实例编号(3306,3307)
/usr/local/mysql/bin/mysqld_multi report //查看所有数据库服务的状态
/usr/local/mysql/bin/mysqld_multi report 实例编号 //查看某个数据库服务的状态
/usr/local/mysql/bin/mysqld_multi start //启动所有数据库服务
关闭实例:
/usr/local/mysql/bin/mysqld_multi --user=admin --password=123456 [/etc/my.cnf文件中指定的] stop 实例编号(3306,3307)
mysqladmin -uroot -S socket文件路径 password "新密码" //无密码策略
mysql -uroot -p新密码 -S socket文件 //连接时候指定socket文件
> grant shutdown on *.* to admin@\'localhost\' identified by \'123456\';
//在各个实例给admin管理用户加上shutdown权限
*********************************************
创建多实例:
step1:全手写my.cnf配置文件
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe //指定进程文件路径
mysqladmin = /usr/local/mysql/bin/mysqladmin //指定管理命令路径
user = admin //此帐户用于多实例关闭时使用,需要在每个实例上创建并授权
password = 123456
[mysqld]
log-bin=/data/3306/mysql-bin
server_id=6
basedir=/usr/local/mysql
datadir=/data/3306
port=3306
socket=/data/3306/mysql.sock
log-error=/data/3306/mysqld.err
pid-file=/data/3306/mysqld.pid
user=mysql
step2:创建相应的目录
mkdir -p /data/{3306,3307}
step3:初始化数据目录
cd /usr/local/mysql/scripts/
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306 --defaults-file=/data/3306/my.cnf
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3307 --defaults-file=/data/3307/my.cnf
step4:更改权限
chown -R mysql.mysql /data
step5:启动实例
./mysqld_safe --defaults-file=/data/3307/my.cnf &
关闭实例:
mysqladmin -uadmin -p123456 -S /data/3307/mysql.sock shutdown
mysqladmin -uroot -S socket文件路径 password "新密码" //无密码策略
mysql -uroot -p新密码 -S socket文件 //连接时候指定socket文件
> grant shutdown on *.* to admin@\'localhost\' identified by \'123456\';
//在各个实例给admin管理用户加上shutdown权限
以上是关于mysql多实例的主要内容,如果未能解决你的问题,请参考以下文章