Permissions problem using PHP with mySQL

software development

#1

I’m having a hard time tracking down what I think is a permissions problem. I’m using php5 with mySQL. I’ve included three things below. The error message, the php code, and mysql session showing I am a mysql user and the absence of the hit_counter database.

The php code is supposed to create the hit_counter database. It didn’t.

Can anyone point me in the right direction? Thanks in advance.
-molly

The error:


Unable to execute the query.

Error code 1044: Access denied for user ‘mollitoff’@‘205.196.208.0/255.255.240.0’ to database ‘hit_counter’


On the following code:


<?php $DBConnect = mysqli_connect("mysql.zackcourtney.com", "mollitoff", "passwordsuppressedforthispost") Or die("

Unable to connect to the database server.

" . "

Error code " . mysqli_connect_errno() . ": " . mysqli_connect_error()) . "

"; $DBName = "hit_counter"; if (!@mysqli_select_db($DBConnect, $DBName)) { $SQLstring = "CREATE DATABASE $DBName"; $QueryResult = mysqli_query($DBConnect, $SQLstring) Or die("

Unable to execute the query.

" . "

Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "

"; echo "

You are the first visitor!

"; mysqli_select_db($DBConnect, $DBName); } $TableName = "count"; $SQLstring = "SELECT * FROM $TableName"; $QueryResult = mysqli_query($DBConnect, $SQLstring); if (!$QueryResult) { $SQLstring = "CREATE TABLE $TableName (countID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY)"; $QueryResult = mysqli_query($DBConnect, $SQLstring) Or die("

Unable to create the table.

" . "

Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "

"; } $SQLstring = "INSERT INTO $TableName VALUES(NULL)"; $QueryResult = mysqli_query($DBConnect, $SQLstring) Or die("

Unable to execute the query.

" . "

Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "

"; $Hits = mysqli_insert_id($DBConnect); echo "

There have been $Hits hits to this page!

"; mysqli_close($DBConnect); ?>

I am able to connect using the mollitoff user on a test database I created (see below) but the php code that I thought would create and populate a database doesn’t seem to work (it also didn’t appear when I used the SHOW DATABASES command, also below).


euro:~> mysql -u mollitoff -p -h mysql.zackcourtney.com test_table
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 204028 to server version: 5.0.18-standard-log

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> SHOW DATABASES;
±-------------------+
| Database |
±-------------------+
| information_schema |
| test_table |
±-------------------+
2 rows in set (0.00 sec)


#2

That is because you do not have permission to create databases directly within MySQL.


#3

Thank you so much for replying. Could you clarify:

Is this because I’ve failed to assign the correct permissions somewhere?

Or are you saying users at dreamhost are not allowed to do this?

And I think there may be something else going on because I went in through ssh mysql monitor and tried to use CREATE DATABASE to create it and got:

mysql> CREATE DATABASE hit_counter;
ERROR 1044 (42000): Access denied for user ‘mollitoff’@‘205.196.208.0/255.255.240.0’ to database ‘hit_counter’

It’s the same error message. I am logged in as user mollitoff already. I created a different database earlier called “test_table” using the same command and it worked.

Here is my output from SHOW DATABASES;

mysql> SHOW DATABASES;

Database
information_schema
test_table

2 rows in set (0.00 sec)


#4

That is the reason.

If you need to create a MySQL database, you have to use the interface provided in the web panel. You cannot create a database directly. ie: Shared users do not have the access to run “CREATE DATABASE” command within MySQL or run “mysqladmin create” on the command line.


yerba# rm -rf /etc
yerba#