首先創建一個表
Use Test;
Create Table TableTest(
`ID` mediumint(8) default '0',
`Name` varchar(100) default ''
) TYPE=MyISAM;
向數據表導入數據
Load Data InFile 'C:/Data.txt' Into Table `TableTest`
常用如下:
Load Data InFile 'C:/Data.txt' Into Table `TableTest` Lines Terminated By '\r\n';
這個語句,字段默認用制表符隔開,每條記錄用換行符隔開,在Windows下換行符為“\r\n”
C:/Data.txt 文件內容如下面兩行:
1 A
2 B
“1”和“A”之間有一個制表符
這樣就導進兩條記錄了。
自定義語法
Load Data InFile 'C:/Data.txt' Into Table `TableTest` Fields Terminated By ',' Enclosed By '"' Escaped By '"' Lines Terminated By '\r\n';
Fields Terminated By ',' Enclosed By '"' Escaped By '"'
表示每個字段用逗號分開,內容包含在雙引號內
Lines Terminated By '\r\n';
表示每條數據用換行符分開
和 Load Data InFile 相反的是
Select * From `TableTest` Into OutFile 'C:/Data_OutFile.txt';
把表的數據導出