#登录MySQL $ mysql -u root -p mysql> create user 'sync'@'%' identified by 'Sync@0000'; # 5.7要求密码必须含有大小写英文,符号和数字 mysql> grant FILe on *.* to 'sync'@'192.168.172.111' identified by 'Sync@0000'; #赋予FILE权限,允许从从库ip访问主库 mysql> grant replication slave on *.* to 'sync'@'192.168.172.111' identified by 'Sync@0000'; #赋予主从同步权限 mysql> flush privileges;
$ service mysqld restart #重启MySQL $ mysql -u root -p #登录mysql mysql> stop slave; #关闭从库 mysql> change master to master_host='192.168.172.110', master_user='sync' ,master_password='Sync@0000', master_log_file='mysql-bin.00001' ,master_log_pos=156; #配置主库信息 mysql> start slave; #开启从库 mysql> show slave status \G; #Slave_IO_Running,Slave_SQL_Running 都为Yes的时候表示配置成功
3、验证主从: 可以在主库上对数据进行操作,再在从库上刷新是否同步;
MySQL的主从配置很简单
Got fatal error 1236 from master when reading data from binary log: ‘Could not find first log file name in binary log index file’系列一: 主库添加log-bin-index 参数后,从库报这个错误:Got fatal error 1236 from master when reading data from binary log: ‘Could not find first log file name in binary log index file’
Got fatal error 1236 from master when reading data from binary log: ‘could not find next log’
可以
1 2 3
stop slave; reset slave; start slave;
常用命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# 创建数据库和用户 create database databasename default charset utf8 collate utf8_general_ci; create user 'username'@'%' identified by 'password'; grant all privileges on databasename.* to 'username'@'%' flush privileges;
# 替换文字 语法:UPDATE 表名 SET 字段名=replace(字段名, '被替换字符串', '新的字符串') ; 示例:UPDATE tb_user SET name=replace( name, '\'', '') ; # 复制表结构 CREATE TABLE targetTable LIKE sourceTable; # 复制表数据 INSERT INTO targetTable SELECT * FROM sourceTable;