下载mysql-5.6.15.tar.gz cmake-2.8.4.tar.gz
(1)先安装cmake(mysql5.5以后是通过cmake来编译的)
#tar -zxv -f cmake-2.8.4.tar.gz #cd cmake-2.8.4 #./configure #make #make install
#mkdir -p /usr/local/mysql //安装mysql
(3)创建mysql用户及用户组
groupadd mysql useradd -r -g mysql mysql
(4)安装mysql
#tar -zxv -f mysql-5.6.15.tar.gz #cd mysql-5.6.15
#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
#make
#make install
2.配置
(1)设置目录权限
# chown -R mysql:mysql /usr/local/mysql
(2)
# cp support-files/my-medium.cnf /etc/my.cnf //源码配置文件放在/usr/local/mysql/my.cnf,如果读取的不是,要考到/etc/my.cnf,或者启动时指向 --default-files=/path
# cd /usr/local/mysql # scripts/mysql_install_db --user=mysql
(4)设置环境变量
在PATH=$PATH:$HOME/bin添加参数为: PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib #source /etc/profile
(5)手动启动mysql
# ./bin/mysqld_safe --user=mysql &
#/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/bx_34_31.err --pid-file=/usr/local/mysql/data/bx_34_31.pid --socket=/tmp/mysqld.sock --port=3306
启动日志写在此文件下:/usr/local/mysql/data/localhost.err 关闭MySQL服务 # mysqladmin -u root -p shutdown //这里MySQL的root用户还没有配置密码,所以为空值。需要输入密码时,直接点回车键即可。(7)修改MySQL的root用户的密码以及打开远程连接
#mysqladmin -uroot -p password xxxxxx //初始设置root密码
#mysqladmin -uroot -p'xxxxxx' password XXXXXX //修改密码
# mysql -u root mysql
mysql>use mysql; mysql>desc user; mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; //为root添加远程连接的能力。 mysql>update user set Password = password('xxxxxx') where User='root'; mysql>select Host,User,Password from user where User='root'; mysql>flush privileges; mysql>exit
接下来设置mysql主从
主服务器上:
1) 给同步用户授权
mysql> GRANT REPLICATION SLAVE ON *.* TO 'tongbu'@'10.16.34.24' IDENTIFIED BY
'123456';
Query OK, 0 rows affected (0.13 sec)
2) 修改主数据库的配置文件my.cnf,开启BINLOG,并设置server-id的值,修改之后必须重启Mysql服务
[mysqld]
log-bin = /usr/local/mysql/log/mysql-bin.log
server-id=1 (谨记主从两台机器的id不同)
3)之后可以得到主服务器当前二进制日志名和偏移量,这个操作的目的是为了在从数据库启动后,从这个点开始进行数据的恢复
mysql> show master status\G;
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 120
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)
ok,以上一切顺利,如果没有出现master的状态,注意my.cnf的位置/etc/my.cnf
3)备份数据库
mysql> flush tables with read lock;
#mysqldump -h127.0.0.1 -p3306 -uroot -p test > /home/chenyz/test.sql
mysql> unlock tables;
从服务器上做如下
1)修改从数据库的my.cnf,增加server-id参数 ,由于mysql-5.1.7后,不支持配置文件配置master信息,只需配置server-id即可,master信息在mysql命令行配置
[mysqld]
server-id=2
mysql-5.1.7之前版本配置如下信息
log_bin = /var/log/mysql/mysql-bin.log
master-host =10.16.34.24
master-user=tongbu
master-pass=123456
master-port =3306
master-connect-retry=60
replicate-do-db =test
2)在从服务器上,启动slave进程
mysql> start slave;
3)在从服务器查看salve status
mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: localhost
Master_User: root
Master_Port: 3306
Connect_Retry: 3
Master_Log_File: mysql-bin.001
Read_Master_Log_Pos: 120
Relay_Log_File: gbichot-relay-bin.001
Relay_Log_Pos: 548
Relay_Master_Log_File: mysql-bin .001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
双Yes即可