整理记录下学习整个瑞吉外卖项目,详细代码可在我的Gitee仓库瑞吉外卖实战克隆下载学习使用!
MySQL主从复制是一个异步的复制过程,底层是基于MySQL数据库自带的二进制日志功能。即一台或多台MySQL数据库(slave从库)从另一台MySQL数据库(Master,主库)进行日志的复制,然后再解析日志并应用到自身,最终实现从库的数据和主库的数据保持一致。此功能是数据库自带功能,无需借助第三方工具。
准备好两台机器。分别安装好MySQL并启动服务成功
service mysql restart
即可。grant replication on *.* to 'xiaoming'@'%' identified by 'root@123456';
MySQL 8.0版本执行语句:CREATE USER 'xiaoming'@'%' IDENTIFIED BY 'root@123456';GRANT ALL PRIVILEGES ON *.* TO 'xiaoming'@'%';
show master status
,记录file和position值,如图vim /etc/mysql/mysql.conf.d/mysqld.cnf
,i进入编辑,修改如图change master to master_host='127.0.0.1',master_user='xiaoming',master_password='root@123456',master_log_file='mysql-bin.000003',master_log_pos=860,get_master_public_key=1;start slave;
,如图show slave status
,如图vim /var/log/mysql/error.log
show variables like 'server_id';
来查看,执行命令set global server_id=4
来修改。