• mysql load data 到 table ERROR 1148 (42000): The used command is not allowed with this MySQL version


    load到mysql服务器中的文件每一行中默认fields格式是以tabs(\t)隔开,for missing values you can use NULL values. To represent these in your text file, use \N(backslash,capital-N), such as
    
    Whistler        Gwen    bird    \N      1997-12-09      \N
    
    the record for Whistler the bird would look like this (where the whitespace between values is a single tab character).
    
    You can specify the column value separator and end of line marker explicitly in the LOAD DATA statement if you wish, but the defaults are tab and linefeed. 
    
    When you want to add new records one at a time, the INSERT statement is useful. In its simplest form, you supply values for each column, in the order in which the columns were listed in the CREATE TABLE statement. with INSERT, you can insert NULL directly to represent a missing value. You do not use \N like you do with LOAD DATA. 
    such as: 
    mysql> INSERT INTO pet
        -> VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);
    
    问题描述:mysql> load data local infile '/home/landen/MahoutTest/ProcessedRating.txt' into table movie_preferences;
    出现异常:ERROR 1148 (42000): The used command is not allowed with this MySQL version
    
    原因:LOAD DATA 默认读的是服务器上的文件,但是加上LOCAL参数后,就可以将本地具有访问权限的文件加载到数据库中。这在带来方便的同时。也带来了以下安全问题:
    
             1、可以任意加载本地文件到数据库。
    
             2、在WEB环境中,客户从WEB服务器连接,用户可以使用LOAD DATA LOCAL语句来读取WEB服务器进程有读访问权限的任何文件(假定用户可以运行SQL服务器的任何命令)。在这种环境中,MySQL服务器的客户实际上是WEB服务器,而不是连接WEB服务器的用户运行的程序。
    
    Solution:
    
    1. 可以用--local-infile=0选项启动mysqld从服务器端禁用所有LOAD DATA LOCAL命令。
    
    即是在/etc/mysql/my.cnf的[mysqld]下面添加local-infile=0选项,如下:
    
    /etc/mysql/my.cnf
    
    # The MySQL server
    
    [mysqld]
    
    port            = 3306
    
    socket          = /tmp/mysql.sock
    
    skip-locking
    
    key_buffer = 16M
    
    max_allowed_packet = 1M
    
    table_cache = 64
    
    sort_buffer_size = 512K
    
    net_buffer_length = 8K
    
    read_buffer_size = 256K
    
    read_rnd_buffer_size = 512K
    
    myisam_sort_buffer_size = 8M
    
    local-infile=0    (增加此选项)
    
    
    2. 对于mysql命令行的客户端,可以通过指定--local-infile[=1]选项启用LOAD DATA LOCAL命令,
    
    或通过--local-infile=0选项禁用。
    
    类似地,对于mysqlimport,--local or -L选项启用本地数据库文件装载。在任何情况下,成功进行本地装载需要服务器启有相关选项。
    
    以下采用第2种方式在mysql命令行的客户端指定--local-infile[=1]选项启用LOAD DATA LOCAL命令,如下:
    root@landen-Lenovo:~# mysql -u root -p --local-infile=1 Movie(具体某个数据库)
    Enter password: 
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 24554
    Server version: 5.5.29-0ubuntu0.12.04.2 (Ubuntu)
    
    Copyright (c) 2000, 2012, 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> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | Movie              |
    | metastore_db       |
    | mysql              |
    | performance_schema |
    | student            |
    | test               |
    +--------------------+
    7 rows in set (0.00 sec)
    
    mysql> use Movie;
    Database changed
    mysql> drop table movie_preferences;
    Query OK, 0 rows affected (0.45 sec)
    
    mysql> create table movie_preferences(
        -> userID integer not null,
        -> movieID integer not null,
        -> preference integer not null default 0,
        -> timestamp integer not null default 0);
    Query OK, 0 rows affected (0.22 sec)
    
    mysql> load data local infile "/home/landen/MahoutTest/ProcessedRating.txt" into table movie_preferences;
    Query OK, 1000209 rows affected (32.99 sec)
    Records: 1000209  Deleted: 0  Skipped: 0  Warnings: 0
    
    mysql> 
    
  • 相关阅读:
    Nginx使用教程(八):使用Nginx缓存之Memcached缓存
    Nginx使用教程(七):使用Nginx缓存之proxy cache
    Nginx使用教程(六):使用Nginx缓存之FastCGI缓存
    Nginx使用教程(五):使用Nginx缓存之缓存静态内容
    Nginx使用教程(四):提高Nginx网络吞吐量之buffers优化
    Nginx使用教程(三):Nginx配置性能优化之I/O和TCP配置
    Nginx使用教程(二):Nginx配置性能优化之worker配置
    添加Nginx为系统服务(设置开机启动)
    Nginx主程序使用介绍
    北美IT求职攻略
  • 原文地址:https://www.cnblogs.com/likai198981/p/3003840.html
Copyright © 2020-2023  润新知