Error 1148 MySQL The used command is not allowed with this MySQL version

前端 未结 5 662
别那么骄傲
别那么骄傲 2020-11-30 10:38

I am using MySQL LOAD DATA LOCAL INFILE command and I get this error:

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1148 The          


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 11:04

    The legacy mysql_connect also has a parameter 'client_flag' that can be used to set the mysql parameter.

    The client_flags parameter can be a combination of the following constants: 128 (enable LOAD DATA LOCAL handling), MYSQL_CLIENT_SSL, MYSQL_CLIENT_COMPRESS, MYSQL_CLIENT_IGNORE_SPACE or MYSQL_CLIENT_INTERACTIVE. Read the section about MySQL client constants for further information. In SQL safe mode, this parameter is ignored. http://php.net/function.mysql-connect

    Example:

    $db = mysql_connect($host, $user, $pass, FALSE, 128);
    

    However, you may also encounter the following error:

    ERROR 29 (HY000): File '/var/www/.../mysql_import.csv' not found (Errcode: 13)
    

    In which case, you may need to check your App Armor settings to allow MySQL access to the import files on the filesystem.

    In particular I added:

      /import/ r,
      /import/* rw,
    

    To give MySQL read/write access to /import

    e.g: Sample App Armor profile

    cat /etc/apparmor.d/usr.sbin.mysqld 
    
    # vim:syntax=apparmor
    # Last Modified: Tue Jun 19 17:37:30 2007
    #include 
    
    /usr/sbin/mysqld {
      #include 
      #include 
      #include 
      #include 
      #include 
    
      capability dac_override,
      capability sys_resource,
      capability setgid,
      capability setuid,
    
      network tcp,
    
      /etc/hosts.allow r,
      /etc/hosts.deny r,
    
      /etc/mysql/*.pem r,
      /etc/mysql/conf.d/ r,
      /etc/mysql/conf.d/* r,
      /etc/mysql/*.cnf r,
      /usr/lib/mysql/plugin/ r,
      /usr/lib/mysql/plugin/*.so* mr,
      /usr/sbin/mysqld mr,
      /usr/share/mysql/** r,
      /var/log/mysql.log rw,
      /var/log/mysql.err rw,
      /var/lib/mysql/ r,
      /var/lib/mysql/** rwk,
      /var/log/mysql/ r,
      /var/log/mysql/* rw,
      /var/run/mysqld/mysqld.pid w,
      /var/run/mysqld/mysqld.sock w,
      /run/mysqld/mysqld.pid w,
      /run/mysqld/mysqld.sock w,
    
      # Custom import folders start
      # These folders will also be read/writeable by mysql.
      /import/ r,
      /import/* rw,
      # Custom import folders end
    
      /sys/devices/system/cpu/ r,
    
      # Site-specific additions and overrides. See local/README for details.
      #include 
    }
    

    After that MySQL could read files from the /import directory.

提交回复
热议问题