使用lv快照 备份
service mysqld stop
fdisk -l
fdisk /dev/sda
p
n
+3G
w
partprobe /dev/sda
pvcreate /dev/sda10
vgcreate vg0 /dev/sda10
lvcreate -L 1G -n lv01 vg0
mkfs.ext3 /dev/vg0/lv01
迁移数据存放目录
cp -rp /data/mysql /test/
mount /dev/vg0/lv01 /data
cp -rp /test/mysql /data/
service mysqld start
-----------
mysql> create database db5;
Query OK, 1 row affected (0.00 sec)
mysql> use db5;
Database changed
mysql> create table t1(id int,name char(30));
Query OK, 0 rows affected (0.03 sec)
mysql> insert into t1 values(1,"tom"),(2,"mike"),(3,"john");
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
加上读锁
mysql> flush tables with read lock;
创建快照
# lvcreate -L 100M -s -n dbbackup /dev/vg0/lv01
解锁
mysql> unlock tables;
把创建的快照挂载到一个目录
# mkdir /mnt/dbbackup
# mount /dev/vg0/dbbackup /mnt/dbbackup/
# cd /mnt/dbbackup
备份
# cp -rp /mnt/dbbackup/mysql /backup/
# umount /mnt/dbbackup/
删除快照
# lvremove /dev/vg0/dbbackup
------------------
日志
# vim /etc/my.cnf
log=select_log
log-slow-queries=slow_log
long_query_time=3
# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin
根据时间恢复
mysql> create table t5(id int);
mysql> insert into t5 values(1);
mysql> insert into t5 values(2);
mysql> insert into t5 values(3);
mysql> insert into t5 values(4);
mysql> insert into t5 values(5);
mysql> delete from t5 where id =2;
# mysqlbinlog mysql-bin.000006|less
#130905 11:25:08 server id 1 end_log_pos 525 Query thread_id=1
exec_time=0 error_code=0
SET TIMESTAMP=1378351508/*!*/;
insert into t5 values(2)
/*!*/;
# at 525
#130905 11:25:08 server id 1 end_log_pos 552 Xid = 11
COMMIT/*!*/;
# at 552
#130905 11:25:11 server id 1 end_log_pos 619 Query thread_id=1
exec_time=0 error_code=0
SET TIMESTAMP=1378351511/*!*/;
BEGIN
/*!*/;
# at 619
# mysqlbinlog --start-date='2013-09-05 11:25:08' --stop-date='2013-09-05 11:25:11' /data/mysql/mysql-bin.000006 |mysql -u root -p
-----------------------------------
根据位置
mysql> create table t6(id int);
Query OK, 0 rows affected (0.01 sec)
mysql> insert into t6 values(1);
Query OK, 1 row affected (0.01 sec)
mysql> insert into t6 values(2);
Query OK, 1 row affected (0.00 sec)
mysql> insert into t6 values(3);
Query OK, 1 row affected (0.00 sec)
删除表
mysql> drop table t6;
Query OK, 0 rows affected (0.04 sec)
mysql> create table t7(id int)
-> ;
Query OK, 0 rows affected (0.01 sec)
mysql> insert into t7 values(1);
Query OK, 1 row affected (0.00 sec)
mysql> insert into t7 values(2);
Query OK, 1 row affected (0.01 sec)
看日志
# mysqlbinlog mysql-bin.000006|less
注意看 end_log_pos 位置
#130905 11:25:08 server id 1 end_log_pos 1454 Xid = 38
COMMIT/*!*/;
# at 1454
#130905 11:45:58 server id 1 end_log_pos 1539 Query thread_id=1 exec_time=0
error_code=0
SET TIMESTAMP=1378352758/*!*/;
create table t6(id int)
/*!*/;
# at 1539
#130905 11:46:12 server id 1 end_log_pos 2079 Xid = 47
COMMIT/*!*/;
# at 2079
#130905 11:47:10 server id 1 end_log_pos 2182 Query thread_id=1 exec_time=0
error_code=0
SET TIMESTAMP=1378352830/*!*/;
DROP TABLE `t6` /* generated by server */
/*!*/;
# at 2182
----------------
# mysqlbinlog --start-position='1454' --stop-position='2079' /data/mysql/mysql-bin.000006 |mysql -u root -p
检查是否恢复成功
------------------------
mysql> purge master logs to "mysql-bin.000006";
//删除000006之前的日志。
mysql> purge master logs before date_sub(current_date,interval 1 day);
//删除一天以前的二进制日志
mysql> reset master;
//重置二进制日志
----------------------------------
AB复制
master 主服务器 192.168.3.2
# vim /etc/my.cnf
skip-name-resolve
log-bin=mysql-bin
server-id = 1
# service mysqld start
# mysql
mysql> grant replication slave,reload,super on *.* to slave@"192.168.3.3" identified by "123";
//ip地址写从服务器的ip地址
mysql> flush privileges;
mysql> flush tables with read lock;
//加读锁
# mysqldump --all-databases -u root -p > /test/all1.sql
# ls -lh /test/all1.sql
-rw-r--r-- 1 root root 85M Sep 5 15:10 /test/all1.sql
//把all1 传到从服务器上
# scp /test/all1.sql 192.168.3.3:/test
---------------------------
slave 从服务器
# vim /etc/my.cnf
server-id = 2
relay_log=relaylog
relay_log_index=relaylog_index
# cd /data/mysql
# rm -rf ./*
# cd /usr/local/mysql55/scripts/
# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql55 --datadir=/data/mysql
# service mysqld start
# mysql -u root -p < /test/all1.sql
-------------------------------------
master 主服务器
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 | 427 | | |
+------------------+----------+--------------+------------------+
-------------------------
slave 从服务器
mysql> change master to master_host="192.168.3.2",master_port=3306,master_user="slave",master_password="123",master_log_file="mysql-bin.000002",master_log_pos=427;
mysql> slave start;
mysql> show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
-------------------------
同步完成以后
在主服务器解锁
mysql> unlock tables;
然后在主服务器建几个表,看从服务器上有没有产生这几个表
--------------------------
如果ab复制失败
在从服务器上删除 master.info ,删除所有relay文件
服务重启。重新做操作。
----------------------
LAMP
# yum install -y php php-mysql mysql-server httpd
# vim /etc/httpd/conf/httpd.conf
391 DirectoryIndex index.html index.html.var index.php
754 AddType application/x-httpd-php .php
# service httpd start
# chkconfig httpd on
# service mysqld start
# chkconfig mysqld on
# mysqladmin password 123
# cd /test
# unzip qq.zip
# ls
discuz.zip flash.rpm qq.zip upload
# cp -prf upload /var/www/html/qq
# chmod -R 777 /var/www/html/qq
# rpm -ivh flash.rpm
# mysql -u root -p
mysql> create database renren;
mysql> use renren;
mysql> source /var/www/html/qq/qqfarm.sql
http://192.168.3.3/qq/install/