此 MySQL 版本不允许使用所使用的命令 [英] The used command is not allowed with this MySQL version

查看:54
本文介绍了此 MySQL 版本不允许使用所使用的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以在尝试了所有不同想法的答案一周后都没有成功,我要问了.这是用于 MySQL 的 LOAD DATA LOCAL INFILE.已经有很多关于此的帖子,但我仍然无法从 Web 浏览器运行它,但我能够从服务器上的 mysql 命令提示符运行它,使用相同的用户并通过连接到相同的数据库.到目前为止我尝试过的

Alright, so after a week of trying all the different ideas answers I have found with no success, I am going to ask. This is for the LOAD DATA LOCAL INFILE, for MySQL. There have been many posts regarding this, but I am still unable to get it work from the web browser, but am able to run it from the mysql command prompt on the server, with the same user and pass connecting to the same database. What I have tried so far

  1. MySQL 5.5 版
  2. Ubuntu 12.04
  3. PHP 5.3 版

在我的.cnflocal-infile=1在 mysqld,mysql,mysql-safe 中loose-local-infile=1 客户端

In my.cnf local-infile=1 in mysqld,mysql,mysql-safe loose-local-infile=1 client

重新启动 MySQL 服务器.在这一点上,我能够从命令提示符运行查询,而以前没有.我已经给出了从 777 访问中提取文件的目录.我已经确认 php.ini 启用了本地文件参数.我已经更新了 apparmor.实际查询:

Restarted MySQL Server. At this point I was then able to run the query from the command prompt, and previously had not. I have given the directory in which the files are being pulled from 777 access. I have confirmed the php.ini has the local file parameter enabled. I have updated apparmor. Actual Query:

LOAD DATA LOCAL INFILE '/var/www/ui/uploads/r_import.csv' INTO TABLE r_data FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 ROWS (first_name,last_name,apt,user_id)

以上查询通过 mysql 命令工作,在与服务器的连接中没有特殊参数.

Above query works from the mysql command with no special arguments in the connection to the server.

如果有人对此有任何想法,我很乐意尝试任何事情......提前致谢.

If anyone has anymore ideas on this, I would be happy to try anything.... Thanks in advance.

<?php
include 'includes/header.php';
if($_FILES['file']['type'] != "application/vnd.ms-excel"){
   die("This is not a CSV file.");
}
elseif(is_uploaded_file($_FILES['file']['tmp_name'])){
    $filename = $_FILES['file']['tmp_name'];
    $name = $_FILES['file']['name'];
    copy( $filename, 'uploads/'.$name ) or die( "Could not copy file!");
    $file_to_import = '/var/www/ui/uploads/'.$name;
   $query = 'LOAD DATA LOCAL INFILE  \''.$file_to_import.'\' INTO TABLE r_data FIELDS TERMINATED BY  \',\' ENCLOSED BY  \'"\' LINES TERMINATED BY  \'\n\' IGNORE 1 ROWS (first_name,last_name,apt,user_id)';
   echo $query;
   $result = mysqli_query($link,$query) or die(mysqli_error($link));
}
else{
   die("You shouldn't be here");
}
?>

推荐答案

$link = mysqli_init();
mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, true);
mysqli_real_connect($link, 'localhost', $username, $password, $database);

数据库的连接字符串对我有用.我在 developerwjk 给出的链接的最后一条评论中找到了它

The connection string to the database is what worked for me. I found it in the last comment in the link given by developerwjk

这篇关于此 MySQL 版本不允许使用所使用的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆