linux centos6.4安装多个mysql实现主从复制
2017-12-13 10:01
1041 查看
有时间整理了一下关于主从复制,大家可以参考一下
LINUX操作系统:centOS7之前
数据库一:
MYSQL版本:mysql-5.0.56
PORT:3306
系统目录:/usr/local/mysql3306
数据库二:
MYSQL版本:mysql-5.1.72
PORT:3307
系统目录:/usr/local/mysql3307
一.安装开发包(使用默认CENTOS更新源):
# yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype*
# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
# su -
# mkdir ~/src
# cd src
# wget http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-5.1/mysql-5.1.73.tar.gz
# wget http://down1.chinaunix.net/distfiles/mysql-5.0.56.tar.gz
# useradd mysql
# mkdir /usr/local/mysql{3306,3307}/data
# mkdir /usr/local/mysql{3306,3307}/log
# chown -R mysql:mysql /usr/local/mysql{3306,3307}/data/
# chown -R mysql:mysql /usr/local/mysql{3306,3307}/log/
# chmod 750 /usr/local/mysql{3306,3307}/data
# chmod 750 /usr/local/mysql{3306,3307}/log
# mkdir -p /usr/local/mysql{3306,3307}/etc
# chown -R mysql.mysql /usr/local/mysql{3306,3307}/etc
# mkdir -p /var/run/mysqld{3306,3307}
# chown -R mysql.mysql /var/run/mysqld{3306,3307}
# mkdir -p /var/lib/mysqld{3306,3307}
# chown -R mysql.mysql /var/lib/mysqld{3306,3307}
# cp /etc/my.cnf /usr/local/mysql{3306,3307}/etc
编译数据库一:# cd ~/src
# tar -zxvf mysql-5.0.56.tar.gz
# cd mysql-5.0.56
./configure --prefix=/usr/local/mysql3306 --with-mysqld-user=mysql --sysconfdir=/usr/local/mysql3306/etc --localstatedir=/usr/local/mysql3306/data --with-tcp-port=3306 -enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --with-extra-charsets=gbk
-with-extra-charsets=all --with-plugins=csv,innobase,myisam,heap --with-unix-socket-path=/tmp/mysql3306.sock
# make
# make install
编译数据库二:# cd ~/src
# tar -zxvf mysql-5.1.71.tar.gz
# cd mysql-5.1.71
./configure --prefix=/usr/local/mysql3307 --with-mysqld-user=mysql --sysconfdir=/usr/local/mysql3307/etc --localstatedir=/usr/local/mysql3307/data --with-tcp-port=3307 -enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --with-extra-charsets=gbk
-with-extra-charsets=all --with-plugins=csv,innobase,myisam,heap --with-unix-socket-path=/tmp/mysql3307.sock
# make
# make install
数据库一配置:
# vi /usr/local/mysql3306/etc/my.cnf
-------------------------------------------------------
[mysqld]
datadir=/usr/local/mysql3306/data
socket=/tmp/mysql3306.sock
user=mysql
port=3306
pid-file=/var/lib/mysqld3306/mysql.pid
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections= 16384
skip-name-resolve
skip-locking
key_buffer = 256M
max_allowed_packet = 32M
table_cache = 3072
thread_cache_size = 256
sort_buffer_size = 16M
read_buffer_size = 4M
read_rnd_buffer_size = 16M
net_buffer_length = 256M
thread_stack = 8M
query_cache_size = 128M
query_cache_limit = 2M
wait_timeout=7200
interactive_timeout=7200
#log
log-error=/usr/local/mysql3306/log/error.log
log=/usr/local/mysql3306/log/mysql.log
long_query_time=2
log-slow-queries= /usr/local/mysql3306/log/slowquery.log
log-bin= /usr/local/mysql3306/log/bin.log
expire_logs_days = 15
sync_binlog = 1
max_binlog_cache_size = 4294967295
local-infile=0
[mysqld_safe]
log-error=/var/log/mysqld3306.log
pid-file=/var/run/mysqld3306/mysqld.pid
数据库二配置:
# vi /usr/local/mysql3307/etc/my.cnf
-------------------------------------------------------
[mysqld]
datadir=/usr/local/mysql3307/data
socket=/tmp/mysql3307.sock
user=mysql
port=3307
pid-file=/var/lib/mysqld3307/mysql.pid
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections= 16384
skip-name-resolve
skip-locking
key_buffer = 256M
max_allowed_packet = 32M
table_cache = 3072
thread_cache_size = 256
sort_buffer_size = 16M
read_buffer_size = 4M
read_rnd_buffer_size = 16M
net_buffer_length = 256M
thread_stack = 8M
query_cache_size = 128M
query_cache_limit = 2M
wait_timeout=7200
interactive_timeout=7200
#log
log-error=/usr/local/mysql3307/log/error.log
log=/usr/local/mysql3307/log/mysql.log
long_query_time=2
log-slow-queries= /usr/local/mysql3307/log/slowquery.log
log-bin= /usr/local/mysql3307/log/bin.log
expire_logs_days = 15
sync_binlog = 1
max_binlog_cache_size = 4294967295
local-infile=0
[mysqld_safe]
log-error=/var/log/mysqld3307.log
pid-file=/var/run/mysqld3307/mysqld.pid
-------------------------------------------------------
直接做软链接
# ln -s /usr/local/mysql3306/lib/mysql /usr/lib/mysql
利用ldconfig导入系统库
# echo "/usr/local/mysql3306/lib" >> /etc/ld.so.conf.d/mysql.conf
# ldconfig
输出mysql的头文件到系统头文件
# ln -s /usr/local/mysql3306/include/mysql /usr/include/mysql
注: 此处只需将一个mysql实例的库文件添加到系统库,无需多次添加
数据库一配置:
# cd /usr/local/mysql3306
# scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql3306/data
数据库二配置:
# cd /usr/local/mysql3307
# scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql3307/data
复制mysql启动脚本到系统服务目录,并更改脚本配置
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld3306
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld3307
# vi /etc/init.d/mysqld3006
---------------------------------------------
basedir=/usr/local/mysql3306
datadir=/usr/local/mysql3306/data
conf=/usr/local/mysql3306/etc/my.cnf
$bindir/mysqld_safe --defaults-file=$conf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
--------------------------------------------
# vi /etc/init.d/mysqld3007
basedir=/usr/local/mysql3307
datadir=/usr/local/mysql3307/data
conf=/usr/local/mysql3307/etc/my.cnf
$bindir/mysqld_safe --defaults-file=$conf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
--------------------------------------------
数据库一配置:
# chkconfig --add mysqld3306 #添加开机启动服务
# chkconfig --level 35 mysqld3306 on #设置mysql启动
数据库二配置:
# chkconfig --add mysqld3307
# chkconfig --level 35 mysqld3307 on
启动
# service mysqld3306 start
# service mysqld3307 start
添加mysql命令集到系统全局变量
注:如果系统之前未安装mysql客户端,可以将编译好的mysql命令集导入系统全局变量
以后就可以直接使用mysql命令集,而不需要使用绝对路径访问.
# echo "PATH=$PATH:/usr/local/mysql3306/bin;export PATH" >> /etc/profile
# source /etc/profile
数据库一:# /usr/local/mysql3306/bin/mysqladmin -u root password 123456 #设置超级管理员密码
# /usr/local/mysql3306/bin/mysql -P3306 -S/tmp/mysql3306.sock -uroot -p123456 #连接数据库
数据库二:
# /usr/local/mysql3307/bin/mysqladmin -u root password 123456 #设置超级管理员密码
# /usr/local/mysql3307/bin/mysql -P3307 -S/tmp/mysql3307.sock -uroot -p123456 #连接数据库
注: 因为加了mysql环境变量,以后系统后台可以直接使用mysql命令登录,这里使用绝对路径是为了规范操作
# mysql -P3307 -S/tmp/mysql3307.sock -uroot -p123456
测试OK
结束语》》》猎场:如果记忆是一个罐头的话,我希望它不会过期,如果一定要加一个日子的话,我希望他是一万年
LINUX操作系统:centOS7之前
数据库一:
MYSQL版本:mysql-5.0.56
PORT:3306
系统目录:/usr/local/mysql3306
数据库二:
MYSQL版本:mysql-5.1.72
PORT:3307
系统目录:/usr/local/mysql3307
一.安装开发包(使用默认CENTOS更新源):
# yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype*
# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
# su -
# mkdir ~/src
# cd src
# wget http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-5.1/mysql-5.1.73.tar.gz
# wget http://down1.chinaunix.net/distfiles/mysql-5.0.56.tar.gz
# useradd mysql
# mkdir /usr/local/mysql{3306,3307}/data
# mkdir /usr/local/mysql{3306,3307}/log
# chown -R mysql:mysql /usr/local/mysql{3306,3307}/data/
# chown -R mysql:mysql /usr/local/mysql{3306,3307}/log/
# chmod 750 /usr/local/mysql{3306,3307}/data
# chmod 750 /usr/local/mysql{3306,3307}/log
# mkdir -p /usr/local/mysql{3306,3307}/etc
# chown -R mysql.mysql /usr/local/mysql{3306,3307}/etc
# mkdir -p /var/run/mysqld{3306,3307}
# chown -R mysql.mysql /var/run/mysqld{3306,3307}
# mkdir -p /var/lib/mysqld{3306,3307}
# chown -R mysql.mysql /var/lib/mysqld{3306,3307}
# cp /etc/my.cnf /usr/local/mysql{3306,3307}/etc
编译数据库一:# cd ~/src
# tar -zxvf mysql-5.0.56.tar.gz
# cd mysql-5.0.56
./configure --prefix=/usr/local/mysql3306 --with-mysqld-user=mysql --sysconfdir=/usr/local/mysql3306/etc --localstatedir=/usr/local/mysql3306/data --with-tcp-port=3306 -enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --with-extra-charsets=gbk
-with-extra-charsets=all --with-plugins=csv,innobase,myisam,heap --with-unix-socket-path=/tmp/mysql3306.sock
# make
# make install
编译数据库二:# cd ~/src
# tar -zxvf mysql-5.1.71.tar.gz
# cd mysql-5.1.71
./configure --prefix=/usr/local/mysql3307 --with-mysqld-user=mysql --sysconfdir=/usr/local/mysql3307/etc --localstatedir=/usr/local/mysql3307/data --with-tcp-port=3307 -enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --with-extra-charsets=gbk
-with-extra-charsets=all --with-plugins=csv,innobase,myisam,heap --with-unix-socket-path=/tmp/mysql3307.sock
# make
# make install
数据库一配置:
# vi /usr/local/mysql3306/etc/my.cnf
-------------------------------------------------------
[mysqld]
datadir=/usr/local/mysql3306/data
socket=/tmp/mysql3306.sock
user=mysql
port=3306
pid-file=/var/lib/mysqld3306/mysql.pid
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections= 16384
skip-name-resolve
skip-locking
key_buffer = 256M
max_allowed_packet = 32M
table_cache = 3072
thread_cache_size = 256
sort_buffer_size = 16M
read_buffer_size = 4M
read_rnd_buffer_size = 16M
net_buffer_length = 256M
thread_stack = 8M
query_cache_size = 128M
query_cache_limit = 2M
wait_timeout=7200
interactive_timeout=7200
#log
log-error=/usr/local/mysql3306/log/error.log
log=/usr/local/mysql3306/log/mysql.log
long_query_time=2
log-slow-queries= /usr/local/mysql3306/log/slowquery.log
log-bin= /usr/local/mysql3306/log/bin.log
expire_logs_days = 15
sync_binlog = 1
max_binlog_cache_size = 4294967295
local-infile=0
[mysqld_safe]
log-error=/var/log/mysqld3306.log
pid-file=/var/run/mysqld3306/mysqld.pid
数据库二配置:
# vi /usr/local/mysql3307/etc/my.cnf
-------------------------------------------------------
[mysqld]
datadir=/usr/local/mysql3307/data
socket=/tmp/mysql3307.sock
user=mysql
port=3307
pid-file=/var/lib/mysqld3307/mysql.pid
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections= 16384
skip-name-resolve
skip-locking
key_buffer = 256M
max_allowed_packet = 32M
table_cache = 3072
thread_cache_size = 256
sort_buffer_size = 16M
read_buffer_size = 4M
read_rnd_buffer_size = 16M
net_buffer_length = 256M
thread_stack = 8M
query_cache_size = 128M
query_cache_limit = 2M
wait_timeout=7200
interactive_timeout=7200
#log
log-error=/usr/local/mysql3307/log/error.log
log=/usr/local/mysql3307/log/mysql.log
long_query_time=2
log-slow-queries= /usr/local/mysql3307/log/slowquery.log
log-bin= /usr/local/mysql3307/log/bin.log
expire_logs_days = 15
sync_binlog = 1
max_binlog_cache_size = 4294967295
local-infile=0
[mysqld_safe]
log-error=/var/log/mysqld3307.log
pid-file=/var/run/mysqld3307/mysqld.pid
-------------------------------------------------------
直接做软链接
# ln -s /usr/local/mysql3306/lib/mysql /usr/lib/mysql
利用ldconfig导入系统库
# echo "/usr/local/mysql3306/lib" >> /etc/ld.so.conf.d/mysql.conf
# ldconfig
输出mysql的头文件到系统头文件
# ln -s /usr/local/mysql3306/include/mysql /usr/include/mysql
注: 此处只需将一个mysql实例的库文件添加到系统库,无需多次添加
数据库一配置:
# cd /usr/local/mysql3306
# scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql3306/data
数据库二配置:
# cd /usr/local/mysql3307
# scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql3307/data
复制mysql启动脚本到系统服务目录,并更改脚本配置
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld3306
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld3307
# vi /etc/init.d/mysqld3006
---------------------------------------------
basedir=/usr/local/mysql3306
datadir=/usr/local/mysql3306/data
conf=/usr/local/mysql3306/etc/my.cnf
$bindir/mysqld_safe --defaults-file=$conf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
--------------------------------------------
# vi /etc/init.d/mysqld3007
basedir=/usr/local/mysql3307
datadir=/usr/local/mysql3307/data
conf=/usr/local/mysql3307/etc/my.cnf
$bindir/mysqld_safe --defaults-file=$conf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
--------------------------------------------
数据库一配置:
# chkconfig --add mysqld3306 #添加开机启动服务
# chkconfig --level 35 mysqld3306 on #设置mysql启动
数据库二配置:
# chkconfig --add mysqld3307
# chkconfig --level 35 mysqld3307 on
启动
# service mysqld3306 start
# service mysqld3307 start
添加mysql命令集到系统全局变量
注:如果系统之前未安装mysql客户端,可以将编译好的mysql命令集导入系统全局变量
以后就可以直接使用mysql命令集,而不需要使用绝对路径访问.
# echo "PATH=$PATH:/usr/local/mysql3306/bin;export PATH" >> /etc/profile
# source /etc/profile
数据库一:# /usr/local/mysql3306/bin/mysqladmin -u root password 123456 #设置超级管理员密码
# /usr/local/mysql3306/bin/mysql -P3306 -S/tmp/mysql3306.sock -uroot -p123456 #连接数据库
数据库二:
# /usr/local/mysql3307/bin/mysqladmin -u root password 123456 #设置超级管理员密码
# /usr/local/mysql3307/bin/mysql -P3307 -S/tmp/mysql3307.sock -uroot -p123456 #连接数据库
注: 因为加了mysql环境变量,以后系统后台可以直接使用mysql命令登录,这里使用绝对路径是为了规范操作
# mysql -P3307 -S/tmp/mysql3307.sock -uroot -p123456
测试OK
结束语》》》猎场:如果记忆是一个罐头的话,我希望它不会过期,如果一定要加一个日子的话,我希望他是一万年
相关文章推荐
- centos7.2 安装 mysql5.7.13&&加密(ssl)实现mysql数据库的主从复制
- centos7.2 安装 mysql5.7.13&&加密(ssl)实现mysql数据库的主从复制 推荐
- php_linux_centos6.4_安装mysql_apache_php
- MySQL实现单机多实例安装并配置主从复制
- CentOS6.8 MySQL 5.6实现主从复制
- linux centos6.4 mysql主从同步配置
- 在linux同一台主机下面搭建两个mysql 实例并实现主从复制 (二)
- centos7.2安装mysql5.7.13实现 ssl 安全连接的主从复制
- linux上使用amoeba实现MySql集群,以及读写分离,主从复制
- Linux系统实现mysql主从复制
- 红帽6.4 64位上实现mysql5.6的主从复制、基于GTID复制、半同步、ssl加密复制以及读写分离 推荐
- centos6.8下mysql5.6源码安装并实现主从同步
- 虚拟机centos6.3 安装 mysql5.6.15 并设置 mysql主从复制
- CentOS6.3 mysql主从复制(注:mysql是通过yum源安装的)
- Centos 6.4 安装mysql-5.6.14-linux-glibc2.5-i686.tar.gz
- Centos7下配置安装mysql5.5主从复制(一主两从)
- linux系统下实现mysql热备份详细步骤(mysql主从复制)
- centos6.5系统编译安装mariadb以及实现主从复制
- Centos 6.4 安装mysql-5.6.14-linux-glibc2.5-i686.tar.gz
- CentOS 6.4 linux下编译安装MySQL5.6.14