MyBB Community Forums

Full Version: [PLEASE HELP] Need PHP Code (MySQL Query) Create MySQL Account Remotely
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
decswxaqz Wrote:
<?php
mysql_connect('[b]db_host[/b]', '[b]db_user[/b]', '[b]db_password[/b]');
mysql_select_db('mysql');

$query = mysql_query("
	INSERT INTO user (`Host`, `User`, `Password`, `Select_priv`, `Insert_priv`, `Update_priv`)
	VALUES ('[b]user_host[/b]', '[b]user_name[/b]', PASSWORD('[b]user_password[/b]'), 'Y', 'Y', 'Y')");
if(!$query)
{
	print_r(mysql_error());
}
else
{
	mysql_query("FLUSH PRIVILEGES");
echo "finished";
}
?>
I know this works because I just made it.
You will need to change the things in bold to your details.

Hi
The code works but its just give the user access to all the databases and not limited them to one.
Then you can use the grant command from before to limit what they have access to.
Hi, can you change the code please so a database isn't assigned to the user, so when they login into PHPMYADMIN they have no databases their, then when they login to my control panel they can create databases their. Thank You.
GRANT SELECT , INSERT , UPDATE , DELETE ON `{the table}` . * TO '{the user}'@'{the server}';

That will grant a user privileges to that database only. Obviously the account has to be created first.

Is that what you were looking for?
No Sorry, I want to create the mysql account without the database.
can anyone please help. Thank You.
CREATE USER '{the user}'@ 'localhost';

GRANT SELECT, INSERT, UPDATE, DELETE ON * . * TO '{the db}'@ '{the server}' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

You can also check out post #4 of this thread for more information.
Pages: 1 2