亚洲综合社区欧美综合色-欧美逼逼一区二区三区-国产老熟女高潮精品网站-国产日韩最新视频在线看

始創(chuàng)于2000年 股票代碼:831685
咨詢熱線:0371-60135900 注冊有禮 登錄
  • 掛牌上市企業(yè)
  • 60秒人工響應(yīng)
  • 99.99%連通率
  • 7*24h人工
  • 故障100倍補償
全部產(chǎn)品
您的位置: 網(wǎng)站首頁 > 幫助中心>文章內(nèi)容

MySQL的主從同步+mysql-zrm備份

發(fā)布時間:  2012/9/5 16:37:26

MySQL的主從同步是一個很成熟的架構(gòu):優(yōu)點為:
①在從服務(wù)器可以執(zhí)行查詢工作(即我們常說的讀功能),降低主服務(wù)器壓力
②在從主服務(wù)器進行備份,避免備份期間影響主服務(wù)器服務(wù)
③當(dāng)主服務(wù)器出現(xiàn)問題時,可以切換到從服務(wù)器
一、實驗環(huán)境
1、IP與主機名
192.168.10.51   db1.linuxidc.com master
192.168.10.52 db2.linuxidc.com slave-
 

2、所需軟件
mysql-5.1.63.tar.gz
3、安裝gcc和相應(yīng)的依賴包
[root@db1 ~]# yum -y install gcc ncurses-devel
4、數(shù)據(jù)庫目錄及其它
my.cnf配置文件     /usr/local/mysql/my.cnf
mysql數(shù)據(jù)庫位置    /usr/local/mysql/data/
socket位置   /usr/local/mysql/tmp/mysql.sock
二、Master配置
1、安裝Mysql
[root@db1 ~]# tar -zxvf mysql-5.1.63.tar.gz -C /usr/src/
[root@db1 ~]# useradd -M -s /sbin/nologin mysql
[root@db1 ~]# cd /usr/src/mysql-5.1.63/
[root@db1 mysql-5.1.63]# vim configure   #把下面行注釋掉
52297 #    $RM "$cfgfile"
[root@db1 mysql-5.1.63]# ./configure --prefix=/usr/local/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase --with-mysqld-user=mysql
[root@db1 mysql-5.1.63]# make
[root@db1 mysql-5.1.63]# make install
2、配置Mysql
[root@db1 mysql-5.1.63]# cp support-files/my-medium.cnf /usr/local/mysql/my.cnf
[root@db1 mysql-5.1.63]# /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
[root@db1 mysql-5.1.63]# chown -R root.mysql /usr/local/mysql
[root@db1 mysql-5.1.63]# chown -R mysql /usr/local/mysql/data/
[root@db1 mysql-5.1.63]# echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf 
[root@db1 mysql-5.1.63]# ldconfig
[root@db1 mysql-5.1.63]# echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
[root@db1 mysql-5.1.63]# source /etc/profile
[root@db1 mysql-5.1.63]# mkdir /usr/local/mysql/tmp
[root@db1 mysql-5.1.63]# chmod 777 /usr/local/mysql/tmp/
[root@db1 mysql-5.1.63]# vim /usr/local/mysql/my.cnf  #修改socket位置
socket          = /usr/local/mysql/tmp/mysql.sock
[root@db1 mysql-5.1.63]# mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &
[root@db1 mysql-5.1.63]# mysql -uroot -p --socket=/usr/local/mysql/tmp/mysql.sock
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.63-log Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> grant replication slave on *.* to 'backup'@'192.168.10.52' identified by 'backuppwd';
Query OK, 0 rows affected (0.00 sec)

mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)

mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 |      265 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
3、打包主庫遷移數(shù)據(jù)
[root@db1 mysql-5.1.63]# cd /usr/local/mysql/
[root@db1 mysql]# tar -zcf data0708.tar.gz ./data/
三、Slave配置
安裝過程如上,步驟省略......
[root@db2 mysql-5.1.63]# vim /usr/local/mysql/my.cnf   #修改server-id
server-id       = 2
將主數(shù)據(jù)庫備份數(shù)據(jù)拷貝過來并解壓到相應(yīng)的目錄
[root@db2 mysql-5.1.63]# mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &
[root@db2 mysql-5.1.63]# mysql -uroot -p --socket=/usr/local/mysql/tmp/mysql.sock
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.63-log Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> change master to master_host='192.168.10.51',master_user='backup',master_password='backuppwd',master_log_file='mysql-bin.000002',master_log_pos=265;
Query OK, 0 rows affected (0.24 sec)

mysql> start slave;
Query OK, 0 rows affected (0.02 sec)

mysql> show slave status\G
......
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
......
四、驗證
1、在Master上面操作
[root@db1 mysql-5.1.63]# mysql -uroot -p --socket=/usr/local/mysql/tmp/mysql.sock
mysql> create database mysqltest;
Query OK, 1 row affected (0.00 sec)

mysql> use mysqltest;
Database changed
mysql> create table user (id int(5),name char(10));
Query OK, 0 rows affected (0.00 sec)

mysql> insert into user values (0001,'xieping');
Query OK, 1 row affected (0.00 sec)

mysql> insert into user values (0002,'huxinxin');
Query OK, 1 row affected (0.00 sec)

mysql> insert into user values (0003,'dingpeng');
Query OK, 1 row affected (0.00 sec)
2、在Slave上操作
[root@db2 mysql-5.1.63]# mysql -uroot -p --socket=/usr/local/mysql/tmp/mysql.sock
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| mysqltest          |
| test               |
+--------------------+
4 rows in set (0.02 sec)

mysql> select id,name from mysqltest.user;
+------+----------+
| id   | name     |
+------+----------+
|    1 | xieping  |
|    2 | huxinxin |
|    3 | dingpeng |
+------+----------+
3 rows in set (0.00 sec)


 


本文出自:億恩科技【1tcdy.com】

服務(wù)器租用/服務(wù)器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]

  • 您可能在找
  • 億恩北京公司:
  • 經(jīng)營性ICP/ISP證:京B2-20150015
  • 億恩鄭州公司:
  • 經(jīng)營性ICP/ISP/IDC證:豫B1.B2-20060070
  • 億恩南昌公司:
  • 經(jīng)營性ICP/ISP證:贛B2-20080012
  • 服務(wù)器/云主機 24小時售后服務(wù)電話:0371-60135900
  • 虛擬主機/智能建站 24小時售后服務(wù)電話:0371-60135900
  • 專注服務(wù)器托管17年
    掃掃關(guān)注-微信公眾號
    0371-60135900
    Copyright© 1999-2019 ENKJ All Rights Reserved 億恩科技 版權(quán)所有  地址:鄭州市高新區(qū)翠竹街1號總部企業(yè)基地億恩大廈  法律顧問:河南亞太人律師事務(wù)所郝建鋒、杜慧月律師   京公網(wǎng)安備41019702002023號
      1
     
     
     
     

    0371-60135900
    7*24小時客服服務(wù)熱線