mysql文件導(dǎo)入導(dǎo)出有2種方式:
1. 導(dǎo)入導(dǎo)出操作SQL文件,通過執(zhí)行SQL語句來完成操作,文件中包含建表語句和一系列的插入語句;
2. 導(dǎo)入導(dǎo)出操作特定格式的文本數(shù)據(jù),該方式文件中僅包含數(shù)據(jù),注意文件的編碼和數(shù)據(jù)庫編碼要兼容,文件編碼應(yīng)該和character_set_database一致,而與set names charaset的charset無任何關(guān)系;

這里只是方式2的操作方法:
導(dǎo)出到文件:
select * from custom into outfile 'e:\custom.txt' FIELDS TERMINATED BY ',' optionally enclosed by '"';

從文件導(dǎo)入: 
load data infile 'e:\custom.txt' replace into table custom;

 load data infile 'e:\custom.txt' replace into table custom fields terminated by ',' optionally enclosed by '"';


從庫中其他表導(dǎo)入:
 insert into tablename1 select * from tablename2;

///////////// 導(dǎo)入導(dǎo)出給定列 ///////////

 load data infile 'e:\custom.txt' replace into table custom fields terminated by ',' optionally enclosed by

'"'(customid,name,sex);

 select customid,name,sex from custom into outfile 'e:\acustom.txt' fields terminated by ',' optionally enclosed

by '"';

////////////////////////

MYSQL的主鍵是放主存的,第一次的時(shí)候執(zhí)行max獲取最大編號,如果插入的時(shí)候沒有就自增,如果插入的時(shí)候指定了主鍵,則判

斷是否大于max,是則設(shè)置主鍵為max,并插入記錄,否則替換或出錯(cuò);如果自增主鍵為null,則仍是自增;
所以導(dǎo)入的時(shí)候,自增主鍵也可以直接導(dǎo)入;

如果導(dǎo)入的時(shí)候出現(xiàn):truncated字樣,則是SQL_MODE問題,修改sql_mode就可以了;

show variables like '%sql_mode%';
set sql_mode='no_auto_create_user,no_engine_substitution';

如出現(xiàn)錯(cuò)誤:ERROR 1262 (01000): Row 6737 was truncated; it contained more data than there were input columns.
如:文件中出現(xiàn),,空字符,正常情況下會出錯(cuò),需要修改sql_mode后才能導(dǎo)入(會有正常警告);