導出數據庫
-- 導出dbname表結構
mysqldump -uroot -p123456 -d dbname > dbname.sql
-- 導出dbname表數據
mysqldump -uroot -p123456 -t dbname > dbname.sql
-- 導出dbname表結構和數據
mysqldump -uroot -p123456 dbname > dbname.sql
導出數據庫中指定表
-- 導出dbname下的test表結構
mysqldump -uroot -p123456 -d dbname test > test.sql
-- 導出dbname下的test表數據
mysqldump -uroot -p123456 -t dbname test > test.sql
-- 導出dbname下的test表結構和數據
mysqldump -uroot -p123456 dbname test > test.sql
還原
-- 創建數據庫
CREATE DATABASE dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
-- 還原數據庫
mysql -uroot -p123456 dbname < /path/dbname.sql
-- 還原數據庫
source dbname.sql
-- 查看表結構
desc wp_users;
show create table wp_users \G;
SELECT INTO OUTFILE導出
SELECT * INTO OUTFILE 'temp.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'
FROM table_name
WHERE createtime < 1382716800;
LOAD DATA 導入
LOAD DATA INFILE '/home/temp.txt'
INTO TABLE table_name
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'
(product_id,uuid,mac,monitor,win_version,ip,createtime) ;
注: 從本地導入遠程服務器需使用LOAD DATA LOCAL INFILE
確保local_infile打開且有權限的情況下LOAD DATA若報錯:message:The used command is not allowed with this MySQL version
1.mysql_connect指定第五個參數128測試,即mysql_connect($host, $user, $pwd, false, CLIENT_LOCAL_FILES)
2.PHP中mysql擴展版本