一、Centos7、Mac安装MySQL#
笔记地址:https://www.cnblogs.com/ZhuChangwu/p/12984153.html
视频串讲地址:https://www.bilibili.com/video/BV19g411N7NR?p=2
二、主从复制原理#
2.1、基于binlog_filename + position#
原理图:
笔记地址:https://mp.weixin.qq.com/s/cSToNVQPK8QCpkjapxNoEw
视频串讲地址:https://www.bilibili.com/video/BV19g411N7NR?p=3
2.2、基于GTID#
原理图:
笔记地址:https://mp.weixin.qq.com/s/V5hU2ATeey871loWQIqHKg
视频串讲地址:https://www.bilibili.com/video/BV19g411N7NR?p=4
三、my.cnf#
[mysqld] # 端口 port = 3306 # 数据目录 datadir=/var/lib/mysql # 错误日志 log-error=/var/log/mysqld.log # 为每张表单独创建一个表空间文件 # 大家常说的表空间到底是什么?究竟什么又是数据表呢? https://mp.weixin.qq.com/s/CwxRjGI843UerF89G_WJ-Q innodb_file_per_table=on innodb_file_format = Barracuda # binlog 相关配置 # 1、MySQL的 bin log有啥用?在哪里?谁写的?怎么配置? # https://mp.weixin.qq.com/s/DN1shuyxPJ6BkE_RLezAnA # 2、了解bin log的写入机制吗?说说你们线上如何调整参数的! # https://mp.weixin.qq.com/s/MtWzoiJtupso5M8z1KUaQQ # 3、bin log有哪些格式?有啥区别?优缺点?线上用哪种格式? # https://mp.weixin.qq.com/s/ar-wVbDi4CYjPI1t6fTjVw log_bin=mysql-bin log-bin-index = mysql-bin.index max_binlog_size = 256M sync-binlog = 1000 binlog-format = ROW # relaylog相关配置 relay_log_recovery = 1 master_info_repository=TABLE relay_log_info_repository=TABLE relay-log = relay-log relay-log-index = relay-log.index sync_relay_log = 1000 max_relay_log_size = 256M # 设置server-id,集群唯一 server-id=1 # pid、socket pid-file=/var/run/mysqld/mysqld.pid socket=/var/lib/mysql/mysql.sock symbolic-links=0
四、测试SQL#
create database test; use test; CREATE TABLE `runoob_tbl` ( `runoob_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `runoob_title` varchar(100) NOT NULL, `runoob_author` varchar(40) NOT NULL, `submission_date` date DEFAULT NULL, PRIMARY KEY (`runoob_id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; INSERT INTO runoob_tbl (runoob_title, runoob_author, submission_date) VALUES("欢迎微信搜索:", "风一样的程序员", NOW());
CHANGE MASTER TO MASTER_HOST='10.4.7.103', MASTER_USER='MySQLsync', MASTER_PASSWORD='MySQLsync123', MASTER_PORT=3306, MASTER_AUTO_POSITION = 1; CHANGE MASTER TO MASTER_HOST='10.4.7.103', MASTER_USER='mysqlsync', MASTER_PASSWORD='mysqlsync123', MASTER_PORT=3306, MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=434; CHANGE MASTER TO MASTER_AUTO_POSITION=0;
grant replication slave on *.* to MySQLsync@"%" identified by "MySQLsync123"; grant replication slave on *.* to mysqlsync@"127.0.0.1" identified by "mysqlsync123"; grant replication slave on *.* to mysqlsync@"%" identified by "mysqlsync123";
五、中间件使用、概念串讲#
脑图:
视频地址:https://www.bilibili.com/video/BV19g411N7NR?p=5
搞明白这几点:
- 跟大家讲明白这样一件事,你以为你是直连的MySQL?其实不是的,你直连的MySQL_Proxy
- Node、分片的概念
- Proxy配置文件的解读
- 演示Proxy的使用
六、总揽启动流程#
- 基于mysql协议,获取主从库的连接
- 将主从库的连接维护进连接池
- 探活机制
视频地址:https://www.bilibili.com/video/BV19g411N7NR?p=6
Notice:跟大家讲明白这样一件事,你以为你是直连的MySQL?其实不是的,你直连的MySQL_Proxy!