mysql本版:mysql-5.5.19.tar.gz (放在了/root 下)
cmake本版:cmake-3.0.2.tar.gz
主库192.168.5.204 从库192.168.5.203
在主服务器安装mysql(先安装cmake,用来编译mysql)
[root@localhost ~]# tar zxvf cmake-3.0.2.tar.gz
[root@localhost ~]# cd cmake-3.0.2
[root@localhost cmake-3.0.2]# ./bootstrap
[root@localhost cmake-3.0.2]# make && make install
[root@localhost ~]# tar zxvf mysql-5.5.19.tar.gz
[root@localhost ~]# cd mysql-5.5.19
[root@localhost mysql-5.5.19]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/usr/local/mysql/etc -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=ON -DWITH_DEBUG=0 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DENABLE_DTRACE=0
[root@localhost mysql-5.5.19]# make && make install
2.添加mysql用户和组
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -g mysql mysql
3.配置文件
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# mkdir etc
[root@localhost mysql]# cp /root/mysql-5.5.19/support-files/my-medium.cnf /usr/local/mysql/etc/
#chown -R mysql:mysql /usr/local/mysql
4.初始化mysql
# cd /usr/local/mysql/scripts/
#./mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
4.启动mysql
# /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/etc/my-medium.cnf &
#echo ‘export PATH=$PATH:/usr/local/mysql/bin’>> /etc/profile
开机自动启动
# echo ‘/bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/etc/my-medium.cnf &‘ >>/etc/rc.local
5.编辑mysql配置文件my-medium.cnf (开启binlog日志,server-id =1)
[root@localhost ~]# vim /usr/local/mysql/etc/my-medium.cnf
重新启动mysql进程
6.登录mysql
[root@localhost ~]# mysql -S /tmp/mysql.sock
mysql> grant replication slave on *.* to repl@‘%‘ identified by ‘repl‘;
mysql> flush privileges;
在主库服务器,查看主日志文件名称和主日志当前POS号
mysql>show master status\G
在从库设置
mysql>stop slave;
mysql>CHANGE MASTER TO MASTER_HOST=‘192.168.5.204‘,MASTER_PORT=3306,MASTER_USER=‘repl‘,MASTER_PASSWORD=‘repl‘ ,MASTER_CONNECT_RETRY=60,MASTER_LOG_FILE=‘mysql-bin.000007‘, MASTER_LOG_POS=1482;
mysql>start slave;
当 看到两个YES时,表示同步成功
#新建库和表测试是否同步
create table test(id int,name char(10));
本文出自 “梦三国” 博客,谢绝转载!
原文地址:http://nmszh.blog.51cto.com/4609205/1565822