首页 / MYSQL / mysql主从同步环境搭建
mysql主从同步环境搭建
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了mysql主从同步环境搭建,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4118字,纯文字阅读大概需要6分钟。
内容图文
![mysql主从同步环境搭建](/upload/InfoBanner/zyjiaocheng/918/d67c651598c64078b6391716ba695181.jpg)
#my.cnf添加内容
vim /etc/my.cnf
添加以内容:
## replication
server_id=195
binlog-ignore-db=mysql
binlog_format=mixed
log-bin=master-mysql-bin
#登录数据服务器,输入密码
mysql -h 主ip -u root -p
use mysql;
#新建同步账号(从数据库服务器IP与用户以及密码)
grant replication slave, replication client on *.* to 'root'@'从ip' identified by 'Nsk123';
#账号权限生效
flush privileges;
#master数据服务器状态
show master status
显示如下信息:
+-------------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------------+----------+--------------+------------------+-------------------+
| master-mysql-bin.000002 | 120 | | mysql | |
+-------------------------+----------+--------------+------------------+-------------------+
#从服务器安装好之后查看主服务器
show processlist\G;
如果显示以下信息则说明安装成功:
*************************** 1. row ***************************
Id: 2
User: root
Host: 从ip:32902
db: NULL
Command: Binlog Dump
Time: 37
State: Master has sent all binlog to slave; waiting for binlog to be updated
Info: NULL
*************************** 2. row ***************************
#在主数据库服务器上新建一个表,看下是不是会立即同步到从数据库对应数据库里面
#从服务器设置
#my.cnf添加内容
vim /etc/my.cnf
添加以内容:
## replication
server-id =194
relay-log=relay-bin
relay-log-index=relay-bin
replicate-ignore-db=mysql
replicate-ignore-db=information_schema
#链接从数据库服务器,输入密码
mysql -h 从ip -u root -p
use mysql
#停止从数据库服务器
stop slave;
#添加主数据库服务器相关信息(主IP,用户名,密码,主binlog文件名称,这个与show master status命令显示的File一致,,MASTER_LOG_POS是主日记文件的行数,show master status#命令显示的Position一致)
CHANGE MASTER TO MASTER_HOST='主ip',MASTER_USER='root',MASTER_PASSWORD='Nsk123',MASTER_LOG_FILE='master-mysql-bin.000002',MASTER_LOG_POS=120;
#显示从数据库服务器状态
show slave status\G;
显示如下信息:
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 主ip
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-mysql-bin.000002
Read_Master_Log_Pos: 120
Relay_Log_File: relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: master-mysql-bin.000002
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB: mysql,information_schema
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 120
Relay_Log_Space: 120
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 1236
Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 195
Master_UUID: 7ed5adb7-0928-11d6-b93f-ec388f720bcb
Master_Info_File: /usr/local/dev/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp: 181215 21:27:17
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
#启动从数据库服务器
start slave;
内容总结
以上是互联网集市为您收集整理的mysql主从同步环境搭建全部内容,希望文章能够帮你解决mysql主从同步环境搭建所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。