LOAD FILE access problem

LOAD FILE access problem

am 26.02.2006 11:43:06 von 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}.

\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.

\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 = << 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\n";
return;
}
function run_mysql_query($query) {
if (mysql_query($query)) {
echo "Success:

" . $query . "
\n

\n";
} else {
echo "Error: " .
mysql_error() . "
\n

$query

\n" . end_body_html();
exit(1);
}
}
==================================

Thanks in advance!

Re: LOAD FILE access problem

am 26.02.2006 22:54:38 von Bill Karwin

"CPD" wrote in message
news:_CfMf.14721$rL5.2660@newssvr27.news.prodigy.net...
> 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.

Re: LOAD FILE access problem

am 27.02.2006 07:40:59 von CPD

I did a SHOW GRANTS and ALL PRIVILEGES have been granted. What else can I be
missing? Thanks again!

"Bill Karwin" wrote in message
news:dtt82s010ce@enews4.newsguy.com...
> "CPD" wrote in message
> news:_CfMf.14721$rL5.2660@newssvr27.news.prodigy.net...
>> 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.
>

Re: LOAD FILE access problem

am 27.02.2006 18:38:33 von Bill Karwin

"CPD" wrote in message
news:%9xMf.61335$PL5.15779@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.

Re: LOAD FILE access problem

am 28.02.2006 00:01:59 von 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" wrote in message
news:dtvdeo02tm3@enews1.newsguy.com...
> "CPD" wrote in message
> news:%9xMf.61335$PL5.15779@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.
>