Load data infile gives me an access denied permissions error. How else can I import a text file into my table in my database?

Asked
Active3 hr before
Viewed126 times

9 Answers

table
90%

I want to import a text file that contains data separated by , . I read on several sources that most people use, "LOAD DATA INFILE". So, I figured it would work for me too. ,That allows me to read the data and create a table and print it. I can also use the INSERT INTO table sql command after using the above to collect the data but I'm not sure how to insert the values into the table. That is, loop through the values for insertion. My data in the txt file doesn't not contain the attributes or headers of what's contained. So... I'm a little confused on how to sort the data into the right columns. , Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers ,IF you gonna do this a few times, you can mount a sql query by importing data into Excel, and use concat to mount the sql lines, and copy/paste to the client and execute. It's not very usefull for lots of tables. If so, it's not hard to use php to upload a csv file and populate the table.

Try something along these lines:

// Connect to Database
$db_Host = "";
$db_Username = "";
$db_Password = "";
mysql_connect($db_Host, $db_Username, $db_Password) or die("MySQL - Connection Error");
mysql_select_db($db_Database) or die("MySQL - Cannot Select Database");

mysql_query("LOAD DATA LOCAL INFILE '/home/username/public_html/Database.txt' INTO TABLE yourtablename") or die("MySQL - Query Error - ".MySQL_Error());

//MySQL is automatically disconnected from when PHP ends.
88%

Is there another way to import a text file into my table in my database? Using SQL or PHP. ,I found this command I can use: ,I want to import a text file that contains data separated by , . I read on several sources that most people use, "LOAD DATA INFILE". So, I figured it would work for me too. ,I read on some other threads that all I had to do was include the full file path and I did but it still didn't work.

I get this permissions error however when I do so. I ran this command and here is what I got:

LOAD DATA INFILE '/public_html/nyccrash.txt'
INTO TABLE nyccrash;

But it gives me this error:

ERROR 1045(28000): Access denied
for user 'username'
@ '%'(using password: YES)

I found this command I can use:

<?php
$row = 1;
$handle = fopen("nyccrash.txt", "r");
echo("<table>");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    echo("<tr>
");
    foreach ($data as $index=>$val) {
        echo("	<td>$val</td>
");
    }
    echo("</tr>
");
}
echo("</table>");
fclose($handle);
load more v
72%

I made sure I gave my txt file permissions: chmod 711,But it gives me this error: ,I get this permissions error however when I do so. I ran this command and here is what I got: ,I want to import a text file that contains data separated by , . I read on several sources that most people use, "LOAD DATA INFILE". So, I figured it would work for me too.

I get this permissions error however when I do so. I ran this command and here is what I got:

LOAD DATA INFILE '/public_html/nyccrash.txt'
INTO TABLE nyccrash;

But it gives me this error:

ERROR 1045(28000): Access denied
for user 'username'
@ '%'(using password: YES)

I found this command I can use:

<?php
$row = 1;
$handle = fopen("nyccrash.txt", "r");
echo("<table>");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    echo("<tr>rn");
    foreach ($data as $index=>$val) {
        echo("t<td>$val</td>rn");
    }
    echo("</tr>rn");
}
echo("</table>");
fclose($handle);
load more v
65%

Reads rows from a text file into the designated table on the database at a very high speed. The file name must be given as a literal string. ,When the statement opens the file, it attempts to read the contents using the default character-set, as defined by the character_set_database system variable. ,The character_set_filesystem system variable controls the interpretation of the filename.,Another example, given the following data (the separator is a tab):

Syntax

LOAD DATA[LOW_PRIORITY | CONCURRENT][LOCAL] INFILE 'file_name' [REPLACE | IGNORE]
INTO TABLE tbl_name
   [CHARACTER SET charset_name]
   [{
         FIELDS | COLUMNS
      }
      [TERMINATED BY 'string']
      [
         [OPTIONALLY] ENCLOSED BY 'char'
      ]
      [ESCAPED BY 'char']
   ]
   [LINES[STARTING BY 'string']
      [TERMINATED BY 'string']
   ]
   [IGNORE number LINES]
   [(col_name_or_user_var, ...)]
   [SET col_name = expr, ...]
load more v
75%

I am trying to run a simple code to mysql db but it’s preventing me to do so. The code is tested on my xampp environment and it works.,the code that i am trying to use is this:,Why are snapshots so slow? It took 35 minutes to make a snapshot. and then to deploy a new droplet based on that snapshot takes a long time it's been saying 30 seconds left for ages now., question Why are snapshots so slow Why are snapshots so slow? It took 35 minutes to make a snapshot. and then to deploy a new droplet based on that snapshot takes a long time it's been saying 30 seconds left for ages now.

the code that i am trying to use is this:

LOAD DATA INFILE '/var/www/laravelapp/storage/app/file.txt'
INTO TABLE test
FIELDS TERMINATED BY '|';

But I know that i am missing smth because I have added the configuration line at my.cnf file
restarted mysql server with the commands:

service mysql restart
or
service mysql stop
service mysql start
or
   /
   etc / init.d / mysql restart

This is part of my.cnf file:

# This was formally known as[safe_mysqld].Both versions are currently parsed.
   [mysqld_safe]
socket = /var/run / mysqld / mysqld.sock
nice = 0

[mysqld]
#
# * Basic Settings
#
secure - file - priv = ""
user = mysql
pid - file = /var/run / mysqld / mysqld.pid
socket = /var/run / mysqld / mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib / mysql
tmpdir = /tmp
lc - messages - dir = /usr/share / mysql
skip - external - locking
#
# Instead of skip - networking the
default is now to listen only on
# localhost which is more compatible and is not less secure.
bind - address = 127.0 .0 .1
#
# * Fine Tuning

Also tried to add it at the end of the file, in other parts, or to change the syntax:

secure - file - priv = " "
secure_file_priv = ""
secure_file_priv = " "

Pls any idea how can I run:

LOAD DATA INFILE
load more v
40%

In the case that LOAD DATA INFILE is disabled in the server or the client, you will get the error message (1148):,A blank User value in either table matches the anonymous user.,Briefly, the server uses the grant tables like this:,Do not ever give anyone (except the mysql root user) access to the user table in the mysql database! This is critical. The encrypted password is the real password in MySQL. Anyone who knows the password which is listed in the user table and has access to the host listed for the account can easily log in as that user.

Try to scan your ports from the Internet using a tool such as nmap. MySQL uses port 3306 by default. This port should be inaccessible from untrusted hosts. Another simple way to check whether your MySQL port is open is to try the following command from some remote machine, where server_host is the hostname of your MySQL server:

shell > telnet server_host 3306
load more v
22%

For example, this gives the permission problem: ,I just ran into this issue as well. I had to add LOCAL to my SQL statement.,Add LOCAL to your statement and the permissions issue should go away. Like so: ,the file you are trying to load does not exist on the machine running mysql server (if using LOAD DATA INFILE); or,

I use MySQL queries all the time in PHP, but when I try

LOAD DATA INFILE
load more v
60%

To read the comma-delimited file, the correct statement is: , If instead you tried to read the file with the statement shown following, it would not work because it instructs LOAD DATA to look for tabs between fields: , When the LOAD DATA statement finishes, it returns an information string in the following format: , To ignore foreign key constraints during the load operation, execute a SET foreign_key_checks = 0 statement before executing LOAD DATA.

The non-LOCAL rules mean that the server reads a file named as ./myfile.txt relative to its data directory, whereas it reads a file named as myfile.txt from the database directory of the default database. For example, if the following LOAD DATA statement is executed while db1 is the default database, the server reads the file data.txt from the database directory for db1, even though the statement explicitly loads the file into a table in the db2 database:

LOAD DATA INFILE 'data.txt'
INTO TABLE db2.my_table;
load more v
48%

Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. ,Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the R Core Team. ,Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. ,This is a guide to importing and exporting data to and from R.

text.Rd: UTF - 8 Unicode English text
text2.dat: ISO - 8859 English text
text3.dat: Little - endian UTF - 16 Unicode English character data,
   with CRLF line terminators
intro.dat: UTF - 8 Unicode text
intro.dat: UTF - 8 Unicode(with BOM) text
load more v

Other "table-undefined" queries related to "Load data infile gives me an access denied permissions error. How else can I import a text file into my table in my database?"