MYSQL 单机多实例安装
mysql可以以多实例的方式,实现一台服务器,运行在不同端口不同数据文件的mysql,它们是相互独立的。
首先
1)创建mysql用户及组
2) 增加环境变量
vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH #增加这行,否则启动服务时会报错
source /etc/profile 使环境变量生效
再运行以下命令
(A)解压安装 shell> cd mysql shell> chown -R mysql . shell> chgrp -R mysql . shell> cp support-files/my-medium.cnf /etc/my.cnf
(B)修改my.cnf
两个实例3306、3307、3308
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
log = /usr/local/mysql/mysqld_multi.log
#user = mysql
#
[mysqld1]
port = 3306
socket = /tmp/mysql3306.sock
pid-file = /tmp/mysql3306.pid
datadir = /usr/local/mysql/data3306
[mysqld27]
port = 3307
socket = /tmp/mysql3307.sock
pid-file = /tmp/mysql3307.pid
datadir = /usr/local/mysql/data3307
[mysqld3]
port = 3308
socket = /tmp/mysql3308.sock
pid-file = /tmp/mysql3308.pid
datadir = /usr/local/mysql/data3308
(C)初始化数据库
scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data3306 --defaults-file=/etc/my.cnf
scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data3307 --defaults-file=/etc/my.cnf
scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data3308 --defaults-file=/etc/my.cnf
设置权限
chown -R mysql mysql /usr/local/mysql/data3306
chown -R mysql mysql /usr/local/mysql/data3307
chown -R mysql mysql /usr/local/mysql/data3308
(D)启动多实例服务
bin/mysqld_multi --defaults-file=/etc/my.cnf start 1
bin/mysqld_multi --defaults-file=/etc/my.cnf start 2
bin/mysqld_multi --defaults-file=/etc/my.cnf start 3
(E)关闭服务
bin/mysqld_multi --defaults-file=/etc/my.cnf stop 1
bin/mysqld_multi --defaults-file=/etc/my.cnf stop 2
bin/mysqld_multi --defaults-file=/etc/my.cnf stop 3
(F)全部启动/关闭
bin/mysqld_multi --defaults-file=/etc/my.cnf start
bin/mysqld_multi --defaults-file=/etc/my.cnf stop
(G) 查看状态
./bin/mysqld_multi --defaults-file=/etc/my.cnf report
(H) 登录不同的实例
./bin/mysql --socket=/tmp/mysql3307.sock #登录3307端口的实例