mysql load 从文件读入数据提示error 1148
mysql创建数据表
create table weblogs(
md5 varchar(32),
url varchar(64),
request_date date,
request_time time,
ip varchar(15))
我的版本是:server version: 5.5.38-0ubuntu0.12.04.1-log (ubuntu)
在使用如下命令导入时会报错:
mysql> load data local infile '/home/hadoop/weblog_entries.txt' into table weblogs fields terminated by '\t' lines terminated by '\n';
error 1148 (42000): the used command is not allowed with this mysql version
提示这个版本的mysql不支持这样导入
解决办法:
hadoop@:~$ mysql -uroot --local-infile=1 -p
enter password:
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 45
server version: 5.5.38-0ubuntu0.12.04.1-log (ubuntu)
copyright (c) 2000, 2014, oracle and/or its affiliates. all rights reserved.
oracle is a registered trademark of oracle corporation and/or its
affiliates. other names may be trademarks of their respective
owners.
type 'help;' or '\h' for help. type '\c' to clear the current input statement.
mysql> use realworld;
reading table information for completion of table and column names
you can turn off this feature to get a quicker startup with -a
database changed
mysql> load data local infile '/home/hadoop/weblog_entries.txt' into table weblogs fields terminated by '\t' lines terminated by '\n';
query ok, 3000 rows affected (1.17 sec)
records: 3000 deleted: 0 skipped: 0 warnings: 0
在连接mysql的时候加上--local-infile的参数 然后导入即可
或者使用如下方式:
mysql -u [youruser] -h [youraddress] -p [yourpassword] [yourdatabase] --local-infile=1 -e [yourcmd]
mysql -uroot -p123456 realworld --local-infile=1 -e load data local infile '/home/hadoop/weblog_entries.txt' into table weblogs fields terminated by '\t' lines terminated by '\n'
原因分析:根据官方的解释是mysql在编译的时候默认把local-infile的参数设为0,就是关闭了从本地load的功能,所以如果需要使用只能自己打开 通过链接的时候把该参数设置为1的方式
另外windows下面的换行符和linux的是不一样的
windows换行是\r\n,,十六进制数值是:0d0a。
linux换行是\n,十六进制数值是:0a
--------------------------------------分割线 --------------------------------------
ubuntu 14.04下安装mysql
《mysql权威指南(原书第2版)》清晰中文扫描版 pdf
ubuntu 14.04 lts 安装 lnmp nginx\php5 (php-fpm)\mysql
ubuntu 14.04下搭建mysql主从服务器
ubuntu 12.04 lts 构建高可用分布式 mysql 集群
ubuntu 12.04下源代码安装mysql5.6以及python-mysqldb
mysql-5.5.38通用二进制安装
--------------------------------------分割线 --------------------------------------
本文永久更新链接地址: