個人測試用格式化文件student.txt 格式是這樣的:html
sss|19|sss
ss|20|ss
ss|22|ssmysql
首先,安裝mysql sudo apt-get install mysql-serversql
1.登陸mysql數據庫,mysql -u root -p回車,輸入密碼便可。數據庫
2.create database testLoadData;oop
3.show databases;測試
4.use testLoadData;this
5.create table test(name varchar(12),age varchar(4),school varchar(20));spa
6.select * from test;.net
7.load data local infile '/home/hadoop/testLoadData/student.txt' into table test fileds terminated by '|' lines terminated by '\n';3d
報錯,ERROR 1148 (42000): The used command is not allowed with this MySQL version
由於Mysql編譯安裝時默認不容許執行這個命令。解決辦法:
1)安裝時加上 --enable-local-infile 參數就能夠了執行了。 ./configure --prefix=/usr/local/mysql --enable-local-infile make make install
2.能夠在執行命中加上--local-infile=1 參數便可解決[1]。 也就是說,輸入exit退出mysql。從新登:
mysql -u root -p testLoadData --local-infile=1;
而後在執行第七步的LoadData.
8.select * from test;
導入成功。
PS:
關於怎麼使用--local-infile=1的問題,糾結了好久。看了[2]才明白的。
[3]爲mysql語句大全。不熟悉mysql還得靠它了。
參考網頁:
[1] http://blog.csdn.net/karen_wang/article/details/6268769【轉】關於MYSQL LOAD DATA LOCAL INFILE 支持問題
[2] http://www.jb51.net/article/33365.htm mysql load data infile 的用法(40w數據 用了3-5秒導進mysql)
[3] http://wenku.baidu.com/view/cf46bac69ec3d5bbfd0a7446.html Mysql語法語句大全