ubuntu上的mysql数据库双机备份设置
配置环境:
myslq 5.5.3 + ubuntu server 12.04
一、配置MySQL主服务器(192.168.0.1)
1.增加一个账号专门用于同步
|
1
|
mysql>grant replication slave on *.* to user@192.168.0.2 identified by '123456'; |
2.接下来备份数据,首先执行如下SQL语句:
|
1
2
3
|
mysql>flush tables with read lock; mysql>mysqldump -u root -p esmartgo > /home/esmartgo.sql |
3.然后将这些数据拷贝到mysql从服务器(192.168.0.2)上,恢复数据,设置好正确的权限及属主等;之后,执行"UNLOCK TABLES"语句来释放锁。
|
1
|
mysql>unlock tables; |
4.修改mysql配置文件
|
1
|
vi /etc/my.cnf |
5.编辑配置文件,在[mysqld]部分添加下面内容
|
1
2
3
4
|
server-id=1 #设置服务器id,为1表示主服务器,注意:如果原来的配置文件中已经有这一行,就不用再添加了。log_bin=mysql-bin #启动MySQ二进制日志系统,注意:如果原来的配置文件中已经有这一行,就不用再添加了。binlog-do-db=esmartgo #需要同步的数据库名,如果有多个数据库,可重复此参数,每个数据库一行binlog-ignore-db=mysql #不同步mysql系统数据库 |
6.重启mysql
|
1
|
service mysqld restart #重启MySQL |
7.进入mysql控制台
|
1
|
mysql -u root -p #进入mysql控制台 |
8.查看主服务器
|
1
|
show master status; |
显示如下信息
|
1
2
3
4
5
6
|
+------------------+----------+--------------+------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000001 | 40538 | esmartgo | |+------------------+----------+--------------+------------------+1 row in set (0.00 sec) |
注意:这里记住File的值:mysql-bin.000001和Position的值:40538,后面会用到。
二、配置MySQL从服务器(192.168.0.2)
1.修改mysql配置文件
vi /etc/my.cnf
2.编辑配置文件,在[mysqld]部分添加下面内容
|
1
2
3
4
|
server-id=2 #配置文件中已经有一行server-id=1,修改其值为2,表示为从数据库。log_bin=mysql-bin #启动MySQ二进制日志系统,注意:如果原来的配置文件中已经有这一行,就不用再添加了。replicate-do-db=esmartgo #需要同步的数据库名,如果有多个数据库,可重复此参数,每个数据库一行replicate-ignore-db=mysql #不同步mysql系统数据库 |
3.重启mysql
service mysqld restart #重启MySQL
4.进入mysql控制台
mysql -u root -p #进入mysql控制台
5.停止slave同步进程
|
1
|
slave stop; #停止slave同步进程 |
6.修改master配置属性
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
change master to master_host='192.168.0.1', master_port = 3306, master_user='user', master_password='123456', master_log_file='mysql-bin.000001', master_log_pos=40358; |
7.查看slave同步信息
|
1
|
show slave status\G |
8.显示结果( Slave_IO_Running: Yes Slave_SQL_Running: Yes说明已经同步成功)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 101.227.252.54 Master_User: user Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 40538 Relay_Log_File: mysqld-relay-bin.000002 Relay_Log_Pos: 36464 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: esmartgo Replicate_Ignore_DB: 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: 40538 Relay_Log_Space: 36621 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: 0Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 11 row in set (0.00 sec) |
ubuntu上的mysql数据库双机备份设置的更多相关文章
- Ubuntu上更改MySQL数据库数据存储目录
之前写过一篇博客"MySQL更改数据库数据存储目录",当时的测试环境是RHEL和CentOS,谁想最近在Ubuntu下面更改MySQL数据库数据存储目录时遇到了之前未遇到的问题,之 ...
- Windows远程连接Ubuntu上的MySQL数据库
原因:mysql安装好后,默认监听3306端口,并且只允许localhost访问,只允许root用户在localhost上登录. 我的环境: Ubuntu16.04 ...
- navicate远程访问ubuntu上的mysql数据库
安装mysql 首先检查系统中是否已经安装了MySQL,在终端里面输入: sudo netstat -tap | grep mysql 如上所示就是正确安装并启动,启动命令为 sudo /etc/in ...
- CentOS 7上更改MySQL数据库存储目录浅析
个人之前总结过两篇文章"MySQL更改数据库数据存储目录"和"Ubuntu上更改MySQL数据库数据存储目录",都是在工作中遇到相关案例后的一个简单总结.当 ...
- MySQL数据库双机热备------主-主备份配置
MySQL数据库双机热备------主-主备份配置 实验环境: 主1数据库 192.168.1.1 centos6.5 x86_64 +MySQL5.5.35 主2数据库192.168.1.2 Wi ...
- [mysql]设置Ubuntu上的MySQL可以远程访问
今天在win10上用django连接安装在Ubuntu上的MySQL上,始终提示错误(can not connect mysql),但是在Ubuntu上访问是没有问题的.于是开始查找原因: 1. 33 ...
- Ubuntu Server下MySql数据库备份脚本代码
明: 我这里要把MySql数据库存放目录/var/lib/mysql下面的pw85数据库备份到/home/mysql_data里面,并且保存为mysqldata_bak_2012_04_11.tar. ...
- 在linux上安装MySQL数据库,并简单设置用户密码,登录MySQL
在新装的Centos系统上安装MySQL数据库. <p><a href="http://www.cnblogs.com/tijun/">提君博客原创< ...
- 在Ubuntu中建立MySQL数据库
最近在做一个关于云计算安全系统的项目,需要用到MySQL数据库,现在把建立数据库的步骤记录下来. 一.用命令在Ubuntu上安装MySQL # sudo apt-get update # sudo a ...
随机推荐
- SQL 课程 连接查询
今天,我主要是对前面所学习过的子查询进行了复习,然后学习了连接查询join on 的内容. 如: select renyuan.code,name,age ,sex , bumen.bname,bce ...
- 水电pd建表
drop table ADMINSTER cascade constraints; /========================================================= ...
- iOS 加载本地的html文件
方法1: self.webView = [[UIWebView alloc]initWithFrame:self.view.bounds]; NSString *path = [[NSBundle ...
- POJ 3347 Kadj Squares (线段覆盖)
题目大意:给你几个正方形的边长,正方一个顶点在x轴上然后边与x轴的夹角为45度,每个正方形都是紧贴的,问从上面看能看的正方形的编号 题目思路:线段覆盖,边长乘上2防止产生小数,求出每个正方形与x轴平行 ...
- SQL多表连接查询以及mysql数据库、sqlserver数据库常见不同点
mysql数据库表及数据准备语句: USE test; DROP TABLE IF EXISTS `teacher_table`; DROP TABLE IF EXISTS `student_tabl ...
- Position & anchorPoint 深入
引言 相信初接触到CALayer的人都会遇到以下几个问题: 为什么修改anchorPoint会移动layer的位置?CALayer的position点是哪一点呢?anchorPoint与positio ...
- hdu_4539_郑厂长系列故事——排兵布阵(状压DP|最大团)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4539 题意:中文,不解释 题解:将每一行的状态压缩,然后进行DP,也可以用最大团做.这里我用的DP # ...
- elasticsearch快照和恢复
摘要:es可以通过简单的命令对索引或者整个集群进行快照和恢复 快照和恢复 Snapshot and restore 模块允许创建单个索引或者整个集群的快照到远程仓库. 在初始版本里只支持共享文件系统的 ...
- List列表 OrderBy
一个条件排序情况 list.OrderBy(item => tem.State); 多个条件的情况下 list.OrderBy(item => new {item.State, item. ...
- Vowel Counting
Vowel Counting Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...