473,387 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

LOAD FILE access problem

CPD
From PHP, doing a DROP TABLE and a CREATE TABLE is successful, but doing a
LOAD FILE keeps failing, with the error "Access denied for user
'db_user'@'localhost' (using password: YES)". The DROP/CREATE code and the
LOAD FILE code are in separate .php files which I am running from my
browser, but both commands are executed with mysql_query(). Don't know what
I'm doing wrong, so I would appreciate any help with this.

Both files run the following code first, which works fine:
==================================
// -----------------------------------------------------------------------
// Connect to MySQL server
// -----------------------------------------------------------------------
$link = mysql_connect($db_host, $db_user, $db_password);
if (! $link) {
die("Could not connect to {$db_user}/{$db_password} on host
{$db_host}:\n" .
mysql_error() . end_body_html());
exit(1);
}
else {
echo "Connected to MySQL on host {$db_host}.<p>\n";
}

// -----------------------------------------------------------------------
// Drop and create PHC_DB database
// -----------------------------------------------------------------------
$drop_db_query = "DROP DATABASE IF EXISTS {$db_name}";

if (run_mysql_query($drop_db_query));

$create_db_query = "CREATE DATABASE IF NOT EXISTS {$db_name}";

if (run_mysql_query($create_db_query));

// -----------------------------------------------------------------------
// Select database
// -----------------------------------------------------------------------
$db_selected = mysql_select_db($db_name, $link);
if (! $db_selected) {
die("Could not select {$db_name} database." .
mysql_error() . end_body_html());
exit(1);
}
else {
echo "Selected {$db_name} database.<p>\n";
}
==================================

Here is the section of DROP/CREATE code, which also works fine:
==================================
// -----------------------------------------------------------------------
// Drop and create REF_USER_LEVELS table
// -----------------------------------------------------------------------
$drop_table_query = "DROP TABLE IF EXISTS ref_user_levels";

run_mysql_query($drop_table_query);

$create_table_query = <<<EOT
CREATE TABLE ref_user_levels (
user_level VARCHAR(10) NOT NULL,
actv_ind ENUM (
'A', -- active
'I' -- inactive
) NOT NULL,
max_counties INT(5),
description VARCHAR(100)
);
EOT;

run_mysql_query($create_table_query);
==================================

Now here is the LOAD FILE code, which fails with
"Error: Access denied for user 'db_user'@'localhost' (using password: YES)
LOAD DATA INFILE '/mysubdir/ref_user_levels.txt' INTO TABLE
ref_user_levels",
where db_user is the value of $db_user, and localhost is the value of
$db_host, as with the DROP/CREATE above.
$dat_file_path is based on DOCUMENT_ROOT, e.g., /mysubdir/
==================================
// -----------------------------------------------------------------------
// Populate REF_USER_LEVELS table
// -----------------------------------------------------------------------
$populate_table_query = "LOAD DATA INFILE
'{$dat_file_path}ref_user_levels.txt' INTO TABLE ref_user_levels";

run_mysql_query($populate_table_query);
==================================

Here are the support functions called:
==================================
function end_body_html() {
echo "\n</body>\n</html>";
return;
}
function run_mysql_query($query) {
if (mysql_query($query)) {
echo "<span style='font-weight:bold;color:green;'>Success:</span>
<pre>" . $query . "</pre>\n<p>\n";
} else {
echo "<span style='font-weight:bold;color:red;'>Error:</span> " .
mysql_error() . "<br>\n<pre>$query</pre><br>\n" . end_body_html();
exit(1);
}
}
==================================

Thanks in advance!

Feb 26 '06 #1
4 2724
"CPD" <no****@email.pls> wrote in message
news:_C******************@newssvr27.news.prodigy.n et...
From PHP, doing a DROP TABLE and a CREATE TABLE is successful, but doing a
LOAD FILE keeps failing, with the error "Access denied for user
'db_user'@'localhost' (using password: YES)".


Are you aware that there are distinct SQL privileges for DROP, CREATE, and
LOAD DATA INFILE?

For DROP/CREATE, your user must have the DROP and CREATE privileges,
respectively.

For LOAD DATA INFILE, your user must have the FILE privilege.

Regards,
Bill K.
Feb 26 '06 #2
CPD
I did a SHOW GRANTS and ALL PRIVILEGES have been granted. What else can I be
missing? Thanks again!

"Bill Karwin" <bi**@karwin.com> wrote in message
news:dt*********@enews4.newsguy.com...
"CPD" <no****@email.pls> wrote in message
news:_C******************@newssvr27.news.prodigy.n et...
From PHP, doing a DROP TABLE and a CREATE TABLE is successful, but doing
a
LOAD FILE keeps failing, with the error "Access denied for user
'db_user'@'localhost' (using password: YES)".


Are you aware that there are distinct SQL privileges for DROP, CREATE, and
LOAD DATA INFILE?

For DROP/CREATE, your user must have the DROP and CREATE privileges,
respectively.

For LOAD DATA INFILE, your user must have the FILE privilege.

Regards,
Bill K.

Feb 27 '06 #3
"CPD" <no****@email.pls> wrote in message
news:%9*******************@newssvr11.news.prodigy. com...
I did a SHOW GRANTS and ALL PRIVILEGES have been granted. What else can I
be missing? Thanks again!


What are the permissions on the file you're trying to load? Can the uid of
your mysqld process read it?

Regards,
Bill K.
Feb 27 '06 #4
CPD
Perms are 644 on the files. The mysqld process should be able to open them,
right? Thanks for following this thread, Bill.

CPD

"Bill Karwin" <bi**@karwin.com> wrote in message
news:dt*********@enews1.newsguy.com...
"CPD" <no****@email.pls> wrote in message
news:%9*******************@newssvr11.news.prodigy. com...
I did a SHOW GRANTS and ALL PRIVILEGES have been granted. What else can I
be missing? Thanks again!


What are the permissions on the file you're trying to load? Can the uid
of your mysqld process read it?

Regards,
Bill K.

Feb 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Eric.Jones | last post by:
I've encountered a strange error with loading delimited files from a Samba (SMB) network drive, has anyone else seen this before? (Platform: WinXP Pro, UDB PE 8015, level 02060106, SAMPLE db) ...
2
by: Sascha | last post by:
Hi there, I searched carefully through the web before finally deciding to post this message, because I could not find a solution for my problem. Hopefully someone will have a hint or explanation...
3
by: ek03 | last post by:
I have a web application that saves/loads XML documents. On occasion, an error is logged on the call to XmlDocument.Load: "process cannot access the file <filepath here> because it is being used by...
22
by: Brett Romero | last post by:
If my UI app uses three DLLs and two of those DLLs reference something named utilities.dll, does the UI app load utilities.dll twice or does the compiler recognize what is going on and load...
4
by: Richard Bysouth | last post by:
Hi I am running a site built on asp.net 1.1 on a windows server 2003 (which is running asp.net 2.0 - shared hosting at my webhost). The site is low traffic and very simple (mostly static text...
2
by: Jeff | last post by:
Hey asp.net 2.0 My asp.net 2.0 project has got a assembly load problem: Some of my web.config settings: <membership defaultProvider="AH_MembershipProvider" userIsOnlineTimeWindow="15">
2
by: peter.drienovsky | last post by:
Hello, let me describe my problem: ENVIRONMENT: ..Net 2.0, MSVS 2005, c#, WinXP SYMPTOMS: If assembly 'AgentDesktop' IS NOT in the (loading) application folder,
4
by: db2admin | last post by:
Hello, If i import data into tables, import will write all warnings in message file and will tell me why any exception row is rejected. I wanted to get exception rows in seperate table which i...
0
by: Andy | last post by:
Thanks Peter, I thought I'd give an update on this problem. My application had 2 assemblies that contained classed for the Data access and business logic layer. It was on one of them that I was...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.