mysql相关笔记

2018-03-10  本文已影响12人  我叫了了

mysql主从复制步骤
1,创建用户
create user 'zhongc'@'192.168.0.%' identified by '123456';
指定访问者host
grant replication slave on *.* to 'zhongc'@'192.168.0.%' identified by '123456';
需要哪些权限

mysql日志

Binary log

mysql5.7版本默认不开启binlog日志
show variables like '%log_bin%'

[mysqld]
server_id=1  # 不能重复
log_bin=mysql-bin  #binlog日志文件的名字 
binlog-format=ROW
binlog-do-db=demo
+---------------------------------+---------------------------------------+
| Variable_name                   | Value                                 |
+---------------------------------+---------------------------------------+
| log_bin                         | ON                                    |
| log_bin_basename                | /usr/local/mysql/data/mysql-bin       |
| log_bin_index                   | /usr/local/mysql/data/mysql-bin.index |
| log_bin_trust_function_creators | OFF                                   |
| log_bin_use_v1_row_events       | OFF                                   |
| sql_log_bin                     | ON                                    |
+---------------------------------+---------------------------------------+

mysql-bin.000001 是数据文件,保存日志数据
mysql-bin.index 是索引文件, 保存日志文件的名字

show binlog enevts in 'filename'
或者
mysqlbinlog filename
查看日志当前状态
show master status

提价日志,生成一个新的日志文件
flush logs
查看所有日志文件
show master logs
删除所有日志文件
reset master

mysqlbinlog mysql-bin.00001 | mysql -uroot -p
mysqlbinlog mysql-bin.000001 -start-position 219 -stop-position 421 | mysql -uroot -p

搭建主从

-- 指定主节点ip,端口,用户

change master to master_host='192.168.0.105',master_port=3306,master_user='zhongc',master_pas sword='123456',master_log_file='mysql-bin.000001',master_log_pos=0;

查看从节点
show salve status\G;
如果
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
就表示成功
-- 启动从节点

主主复制

HaProxy

KeepAlived

Mycat

上一篇下一篇

猜你喜欢

热点阅读