修复SQLite-database disk image is malformed

运转某些SQL语句出错database disk image is malformed

证实SQLite的中间数据格式,已经磨损

sqlite> PRAGMA integrity_check;

*** in database main ***

Main freelist: 3 of 3 pages missing from overflow list starting at 0

解磁盘空间不够的由来
修复步骤
$ sqlite3 backup.sqlite
sqlite> .output “_temp.tmp”
sqlite> .dump
sqlite> .quit
$ sqlite3 new.sqlite
sqlite> .read “_temp.tmp”
sqlite> .quit
虽将左的backup.sqlite修复吗new.sqlite了

其它一样栽更快之修复方法

$echo “.dump” | sqlite3 old.db | sqlite3 new.db

直接将 old.db 修复为 new.db

或者

sqlite3 newsfeed.db .dump > newsfeed.sql

sqlite3 newsfeed.db < newsfeed.sql

请参考  http://www.sqlite.org/faq.html#q21

http://www.sqlite.org/sqlite.html

PHP使用popen调用sqlite shell来落实修复

$handle = popen(“mv ../backup.sqlite bad.sqlite && sqlite3 bad.sqlite
.dump | sqlite3 good.sqlite && mv good.sqlite ../backup.sqlite”, ‘r’);
$read = fread($handle, 4096);
echo $read;
pclose($handle);

 

 

压缩

sqlite3 my.sqlite 'VACUUM;'

 

原文:http://zhiwei.li/text/2010/08/%e4%bf%ae%e5%a4%8dsqlite-database-disk-image-is-malformed/
网站地图xml地图