一、MySQ主从复制(主库写入数据,从库读取数据)
MySql官方下载地址:http://dev.mysql.com/downloads/mysql/
MySql常用命令:
设置密码 UPDATE USER SET PASSWORD=PASSWORD('123456') WHERE USER='root';
使用命令show global variables like 'port';查看端口号
使用“GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;”命令可以更改远程连接的设置。
安装mysql服务命:mysqld install mysql 启动mysql命令:net start mysql
1.主库配置:
第一步:my.ini配置文件
[mysqld]
server-id = 1
log-bin = mysql-bin
binlog-do-db = test
binlog-ignore-db = mysql
binlog-ignore-db = information_schema
binlog-ignore-db = performance_schema
第二步:给主数据库开启可以让从数据库访问的账户
SHOW MASTER STATUS;
GRANT REPLICATION SLAVE ON *.* TO '用户名'@'%' IDENTIFIED BY '密码';
SELECT * FROM USER WHERE USER='用户名';
SHOW VARIABLES LIKE '%log_bin%';
2.从库配置:
第一步:my.ini配置文件
[mysqld]
server-id = 2
replicate-do-db=test
relay-log=slave-relay-bin
relay-log-index=slave-relay-bin.index
第二步:从库连接主数据库进行数据同步
STOP SLAVE
RESET SLAVE;
CHANGE MASTER TO
MASTER_HOST="主数据库IP地址",
MASTER_PORT=3306,
MASTER_USER="用户名",
MASTER_PASSWORD="密码",
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=120;
START SLAVE;
SHOW SLAVE STATUS
二、MyCAT实现MySQL的读写分离
http://www.cnblogs.com/ivictor/p/5131480.html
三、MySQL需要不断进行拆库拆表