步骤如下:
一、编译安装两个mysql,步骤如下
安装第一个数据库(主数据库)
(红色部分为默认数据库文件路径,可改成其他如:data、var等)
tar zxvf mysql-6.0.11-alpha.tar.gz
cd mysql-6.0.11-alpha
./configure --prefix=/usr/local/mysql3306 --sysconfdir=/usr/local/mysql/etc --with-tcp-port=3306 --localstatedir=/usr/local/mysql3306/var--with-unix-socket-path=/tmp/mysql3306.sock --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312,binary --enable-thread-safe-client --with-plugins=innobase --with-mysqld-user=mysql --with-charset=utf8 --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static
make && make install
安装第二个数据库(从数据库)
tar zxvf mysql-6.0.11-alpha.tar.gz
cd mysql-6.0.11-alpha
./configure --prefix=/usr/local/mysql3307 --sysconfdir=/usr/local/mysql3307/etc --with-tcp-port=3307 --localstatedir=/usr/local/mysql3307/var--with-unix-socket-path=/tmp/mysql3307.sock --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312,binary --enable-thread-safe-client --with-plugins=innobase --with-mysqld-user=mysql --with-charset=utf8 --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static
make && make install
如需支持所有字符集 修改为:--with-extra-charsets=all 即可
二、分别初始化数据库脚本(在编译目录执行下)
scripts/mysql_install_db --basedir=/usr/local/mysql3306/ --user=mysql
scripts/mysql_install_db --basedir=/usr/local/mysql3307/ --user=mysql
注:可用--datadir=PATH参数指定数据库文件路径,默认为编译时-- localstatedir
三、修改从库配置文件
拷贝配置文件:
cp /usr/local/software/mysql-6.0.11-alpha/support-files/my-medium.cnf /usr/local/mysql/etc/my.cnf
cp /usr/local/software/mysql-6.0.11-alpha/support-files/my-medium.cnf /usr/local/mysql3307/etc/my.cnf
四、修改各个数据库的my.cnf文件
主要内容如下:
添加InnoDB支持:
[client]
#password = your_password
port = 3307 --数据库端口号
socket = /tmp/mysqls.sock --sock文件路径
default-character-set=utf8 --客户端UTF8连接
[mysqld]
port = 3307 --数据库端口号
socket = /tmp/mysqls.sock --sock文件路径
default-storage-engine=INNODB
default-character-set=UTF8 --默认字符集
init_connect='SET NAMES utf8' --以UTF8连接
skip-name-resolve --取消DNS反向解析
lower_case_table_names=1 --不区分表名大小写
启动数据库(进入各自目录)
主:./scripts/mysqld_safe &
从:./scripts/mysqld_safe &
配置开启自动:
cp /usr/local/software/mysql-6.0.11-alpha/support-files/mysql.server /etc/init.d/mysql
cp /usr/local/software/mysql-6.0.11-alpha/support-files/mysql.server /etc/init.d/mysql3307
修改/etc/init.d/mysql3007中basedir与datadir为即可
basedir=/usr/local/mysql3307
datadir=/usr/local/mysql3307/var
停止数据库
主:./mysqladmin shutdown
从:./mysqladmin shutdown