手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

MySQL load 从文件读入数据提示ERROR 1148

[日期:2014-10-23] 来源:Linux社区  作者:sunflower_cao [字体:大 中 小]

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不支持这样导入

解决办法:http://dev.mysql.com/doc/refman/5.5/en/load-data-local.html

hadoop@www.linuxidc.com:~$ mysql -uroot<span style="background-color: rgb(255, 0, 0);"> --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 http://www.linuxidc.com/Linux/2014-05/102366.htm

《MySQL权威指南(原书第2版)》清晰中文扫描版 PDF http://www.linuxidc.com/Linux/2014-03/98821.htm

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL http://www.linuxidc.com/Linux/2014-05/102351.htm

Ubuntu 14.04下搭建MySQL主从服务器 http://www.linuxidc.com/Linux/2014-05/101599.htm

Ubuntu 12.04 LTS 构建高可用分布式 MySQL 集群 http://www.linuxidc.com/Linux/2013-11/93019.htm

Ubuntu 12.04下源代码安装MySQL5.6以及Python-MySQLdb http://www.linuxidc.com/Linux/2013-08/89270.htm

MySQL-5.5.38通用二进制安装 http://www.linuxidc.com/Linux/2014-07/104509.htm

--------------------------------------分割线 --------------------------------------

本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-10/108338.htm

linux
相关资讯       MySQL Error  MySQL ERROR 1148 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款