052010

用 mysqldump 做線上即時備份,通常 InnoDB 的資料只有出現1~2筆,如果要儘可能把完整的資料匯出,可以加上 --single-transaction,備份前 mysqldump 會先執行 BEGIN ,取得 READ LOCK 後,便能確定資料在執行 mysqldump 的過程中不會受到其它連線對 InnoDB 存取的干擾,也能 Dump 出較完整的資料。(使用此參數需有 READ LOCK 權限)

mysqldump --single-transaction --all-databases > all_db.sql

注意:
1.表單較大時可以加上 --quick
2.MySQL Cluster 不支援 --single-transaction

然而使用 --single-transaction 時最好搭配 --flush-logs 及 --master-data 來維持 Binary Log 的完整性。(使用這二個參數皆需有 RELOAD 權限)

mysqldump --single-transaction --flush-logs --master-data --all-databases > all_db.sql

Binary Log 採用的是遞增備份,--flush-logs 便是把目前的 Binary Log 給 flush 出來 (若目前 MASTER_LOG_FILE 已經到 mysql-bin.000005,產生出來的檔案便是 mysql-bin.000006),完成之後才進行 Dump 的作業。

而 --master-data (預設值為1) 則是在 Dump 出來的 SQL 語法中加入下面這一行,以記錄目前 Dump 的時間點。

CHANGE MASTER TO MASTER_LOG_FILE=mysql-bin.000006',MASTER_LOG_POS=4;

如果在未來執行匯入時 SQL 語法時, MySQL 便能很清楚的知道這次 Dump 出來的 SQL 在 Binary Log 中是屬於哪個位置。

註: 若不需理會 Binary Log 的位置時 (例如進行完整備份作業),只要將 --master-data 設為 2 便會將 CHANGE MASTER 給註解起來純供參考用。

转载自:http://www.neo.com.tw/archives/1122

Posted by admin Tagged with:
252010

The default maximum allowed packget size is 1MB, so if you store some large binaries in your database you might get some problems. All you need to do is re-set the maximum size to a larger number.

Macintosh:trunk jennyfong$ mysql -uroot database_name < database_backup.sql

ERROR 1153 (08S01) at line 2365: Got a packet bigger than 'max_allowed_packet' bytes
Macintosh:trunk jennyfong$ mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 5.0.86 MySQL Community Server (GPL)

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

mysql> set global net_buffer_length=10000000;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> set global max_allowed_packet=1000000000;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
Macintosh:trunk jennyfong$ mysql -uroot database_name < database_backup.sql

show variables like 'max_allowed_packet';

Posted by admin Tagged with:
062010

wget http://www.percona.com/mysql/xtrabackup/1.0/source/xtrabackup-1.0-56.rhel5.src.rpm
mkdir -p /usr/src/redhat/SOURCES/
rpm -i xtrabackup-1.0-56.rhel5.src.rpm
cd /usr/src/redhat/SOURCES/
tar xf xtrabackup-1.0.tar.gz
cd xtrabackup-1.0
./configure
make
cd innobase/xtrabackup/
make
make install

/usr/bin/innobackupex-1.5.1 --help

Posted by admin Tagged with: ,
十二 082009

今天碰到数据库出错

Got error 28 from storage engine

查了一下,数据库文件所在的盘应该没事,应该是数据库用的临时目录空间不够

引用
磁盘临时空间不够导致。
解决办法:
清空/tmp目录,或者修改my.cnf中的tmpdir参数,指向具有足够空间目录

上面的说法应该比较清楚,还有一个类似的:

引用
mysql报以下错的解决方法

ERROR 1030 (HY000): Got error 28 from storage engine

出现此问题的原因:临时空间不够,无法执行此SQL语句

解决方法:将tmpdir指向一个硬盘空间很大的目录即可

原创内容如转载请注明:来自 阿权的书房
本帖地址:http://www.aslibra.com/blog/read.php/794.htm

Posted by admin Tagged with: ,
十二 052009

在Linux上把MySQL库导出为sql和txt,在Linux上是很容易导入

mysql -u root -ppassword  dbname < db_struc.sql

mysqlimport --local -uroot -ppassword dbname `find . -name "*.txt"`

Windows下麻烦了,没有find,又不支持*.txt

后来想到办法,建了个bat文件

用替换的方法将文件修改为

mysqlimport -uroot -ppassword dbname d:\dump\table1.txt

mysqlimport -uroot -ppassword dbname d:\dump\table2.txt

.

.

.

然后把bat文件放到mysql下的bin目录,执行该批处理就可以了

Posted by admin Tagged with: