当前位置: 数据库>mysql
Linux下安装Mysql多实例作为数据备份服务器实现多主到一从多实例的备份
来源: 互联网 发布时间:2014-09-06
本文导语: 1、从MYSQL官方下载MYSQL的源码版本【一定要是源码版本】 2、按以下代码键入LINUX命令行 代码如下: [注] 添加mysql组和用户 #groupadd mysql #useradd -g mysql mysql [注] 解包到/usr/local # tar -xzf mysql-standard-4.1.9-pc-linux-gnu-i686.tar.gz -C /usr/local ...
1、从MYSQL官方下载MYSQL的源码版本【一定要是源码版本】
2、按以下代码键入LINUX命令行
[注] 添加mysql组和用户
#groupadd mysql
#useradd -g mysql mysql
[注] 解包到/usr/local
# tar -xzf mysql-standard-4.1.9-pc-linux-gnu-i686.tar.gz -C /usr/local
[注] 建立软链接,方便操作(此处给此连接命名为mysql001,也可为其它的名字)
#cd /usr/local
#ln -s mysql-standard-5.0.15-linux-i686-glibc23 mysql001
#cd mysql001
#scripts/mysql_install_db
#chown -R root .
#chown -R mysql data
#chgrp -R mysql .
[注] 复制data,以供单版本多实例分配
#cp -a data data_1
#cp -a data data_2
[注] 添加多实例配置文件
#cd /usr/local/mysql001/bin
#cat >my_multi.cnf
[注] 以下是my_multi.cnf的配置信息,可依此复制
[mysqld_multi]
mysqld = /usr/local/mysql001/bin/mysqld_safe
mysqladmin = /usr/local/mysql001/bin/mysqladmin
user = root
password = root
[mysqld1]
socket = /tmp/mysql_001.sock
port = 3301
pid-file = /usr/local/mysql001/data_1/hostname.pid
datadir = /usr/local/mysql001/data_1
log = /usr/local/mysql001/data_1/hostname.log
user = mysql
# slave setting
server-id = 2
master-host = 192.168.1.85
master-port = 3306
master-user = backup
master-password = 123456
replicate-do-db = gs_database
replicate-do-db = gs_log
master-connect-retry=30
[mysqld2]
socket = /tmp/mysql_5_2.sock
port = 3302
pid-file = /usr/local/mysql001/data_2/hostname.pid
datadir = /usr/local/mysql001/data_2
log = /usr/local/mysql001/data_2/hostname.log
user = mysql
# slave setting
server-id = 3
master-host = 192.168.1.69
master-port = 3306
master-user = backup
master-password = 123
replicate-do-db = gs_databaes
replicate-do-db = gs_log
master-connect-retry=30
CTRL+D退出。
#vi /etc/profile # 添加系统环境变量。
export MYSQL_HOME=/usr/local/mysql001/bin
export PATH=$PATH:$MYSQL_HOME
重启系统让环境变量生效。
添加至开机自动启动【此处可不添加,依个人情况决定是否需要设置开机自动启动】
vi /etc/rc.local
# 添加
mysqld_multi --defaults-extra-file=/usr/local/src/mysql_dir/bin/my_multi.cnf start 1,2
3、其它一些技巧
# 访问某个实例:
mysql -u root -S /tmp/mysql_5_1.sock -p
# 设置各个实例密码:
mysqladmin -u root password 'root' -S /tmp/mysql_5_1.sock
# 手动启动各个实例:
mysqld_multi --defaults-extra-file=/usr/local/src/mysql_dir/bin/my_multi.cnf start 1,2
# 停止各个实例:
mysqld_multi --defaults-extra-file=/usr/local/src/mysql_dir/bin/my_multi.cnf stop 1,2
# 参考文章
http://blog.liuts.com/post/13/
由于第一次接触LINUX,花了三天时间才算有所成就,发出来希望可以给大伙带来方便
2、按以下代码键入LINUX命令行
代码如下:
[注] 添加mysql组和用户
#groupadd mysql
#useradd -g mysql mysql
[注] 解包到/usr/local
# tar -xzf mysql-standard-4.1.9-pc-linux-gnu-i686.tar.gz -C /usr/local
[注] 建立软链接,方便操作(此处给此连接命名为mysql001,也可为其它的名字)
#cd /usr/local
#ln -s mysql-standard-5.0.15-linux-i686-glibc23 mysql001
#cd mysql001
#scripts/mysql_install_db
#chown -R root .
#chown -R mysql data
#chgrp -R mysql .
[注] 复制data,以供单版本多实例分配
#cp -a data data_1
#cp -a data data_2
[注] 添加多实例配置文件
#cd /usr/local/mysql001/bin
#cat >my_multi.cnf
[注] 以下是my_multi.cnf的配置信息,可依此复制
[mysqld_multi]
mysqld = /usr/local/mysql001/bin/mysqld_safe
mysqladmin = /usr/local/mysql001/bin/mysqladmin
user = root
password = root
[mysqld1]
socket = /tmp/mysql_001.sock
port = 3301
pid-file = /usr/local/mysql001/data_1/hostname.pid
datadir = /usr/local/mysql001/data_1
log = /usr/local/mysql001/data_1/hostname.log
user = mysql
# slave setting
server-id = 2
master-host = 192.168.1.85
master-port = 3306
master-user = backup
master-password = 123456
replicate-do-db = gs_database
replicate-do-db = gs_log
master-connect-retry=30
[mysqld2]
socket = /tmp/mysql_5_2.sock
port = 3302
pid-file = /usr/local/mysql001/data_2/hostname.pid
datadir = /usr/local/mysql001/data_2
log = /usr/local/mysql001/data_2/hostname.log
user = mysql
# slave setting
server-id = 3
master-host = 192.168.1.69
master-port = 3306
master-user = backup
master-password = 123
replicate-do-db = gs_databaes
replicate-do-db = gs_log
master-connect-retry=30
CTRL+D退出。
代码如下:
#vi /etc/profile # 添加系统环境变量。
export MYSQL_HOME=/usr/local/mysql001/bin
export PATH=$PATH:$MYSQL_HOME
重启系统让环境变量生效。
添加至开机自动启动【此处可不添加,依个人情况决定是否需要设置开机自动启动】
代码如下:
vi /etc/rc.local
# 添加
mysqld_multi --defaults-extra-file=/usr/local/src/mysql_dir/bin/my_multi.cnf start 1,2
3、其它一些技巧
# 访问某个实例:
mysql -u root -S /tmp/mysql_5_1.sock -p
# 设置各个实例密码:
mysqladmin -u root password 'root' -S /tmp/mysql_5_1.sock
# 手动启动各个实例:
mysqld_multi --defaults-extra-file=/usr/local/src/mysql_dir/bin/my_multi.cnf start 1,2
# 停止各个实例:
mysqld_multi --defaults-extra-file=/usr/local/src/mysql_dir/bin/my_multi.cnf stop 1,2
# 参考文章
http://blog.liuts.com/post/13/
由于第一次接触LINUX,花了三天时间才算有所成就,发出来希望可以给大伙带来方便