[SOLVED] Creating mysql db user
Moderator: General Moderators
[SOLVED] Creating mysql db user
Hello all.
I'm trying to automate the the user creation on mysql db.
As you may know the db which hold the user information and the privilages is called 'mysq'l and the table is 'user'.
Everything works smoothly and the user is created but when I try to connect to my db via this user I get denied.
If I put it manually (via phpmyadmin) everything works
any ideas?
I'm trying to automate the the user creation on mysql db.
As you may know the db which hold the user information and the privilages is called 'mysq'l and the table is 'user'.
Everything works smoothly and the user is created but when I try to connect to my db via this user I get denied.
If I put it manually (via phpmyadmin) everything works
any ideas?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
Hmmm...
Something is strange.
I've tried to manual enter a user to mysql db and it didn't work either.
I have other users I have entered before and are working fine...
It can't be my code because the manual doesn't work as well.
And i'm putting it on the right db becasue I can see there the records of the users that does work...
Something is strange.
I've tried to manual enter a user to mysql db and it didn't work either.
I have other users I have entered before and are working fine...
It can't be my code because the manual doesn't work as well.
And i'm putting it on the right db becasue I can see there the records of the users that does work...
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
Code: Select all
// database connection values
$host = "localhost";
$user = "your_mysql_username";
$password = "your_mysql_password";
//connection variables completeed
// establishing connections
mysql_connect ($host, $user, $password);
//connection established-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
Code: Select all
// database connection values
$host = "localhost";
$user = "your_mysql_username";
$password = "your_mysql_password";
//connection variables completeed
// establishing connections
mysql_connect ($host, $user, $password);
//connection established-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
my code
here is my code:
When I say manual I mean via phpmyadmin
Code: Select all
<?php
mysql_select_db("mysql",$db);
$sqlDbUsers="INSERT INTO user(Host,User,Password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Reload_priv,Shutdown_priv,Process_priv,File_priv,Grant_priv,References_priv,Index_priv,Alter_priv) VALUES ('localhost','superuser','5194351','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y')";
mysql_query($sqlDbUsers) or die('Query failed: ' . mysql_error());
mysql_close($db);
$db = @mysql_connect("localhost","superuser","5194351") or die("Could not connect: " . mysql_error());
if(!mysql_select_db("myDB",$db))
{
echo "<br>No database selected<br>". mysql_error();
exit;
}
?>Well you are trying to connect to the MySQL database with a username that is held in the table. This is not how it works. You always connect with your username and your password.
See, you are inserting the username here:
and then trying to connect to the database using that usename and password:
You can only connect to the MySQL database with the username given to you by your host. Unless these are your username and password for the actual database, then you might want to edit them . . .
See, you are inserting the username here:
Code: Select all
<?php
$sqlDbUsers="INSERT INTO user(Host,User,Password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Reload_priv,Shutdown_priv,Process_priv,File_priv,Grant_priv,References_priv,Index_priv,Alter_priv) VALUES ('localhost','superuser','5194351','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y')";
?>Code: Select all
<?php
$db = @mysql_connect("localhost","superuser","5194351") or die("Could not connect: " . mysql_error());
?>