Page 1 of 1

Creating new MySQL users with PHP?

Posted: Tue Oct 11, 2005 12:27 am
by johnhaze
I'm familiar with creating new databases with PHP, but can I create new users as well?
I scoped out php.net but couldn't find anything relevant. Google wasn't much help either

I know it's possible because all the popular web hosting backpanels let you do it (cpanel, plesk..). The question is what are they doing it with? Are they using a web language or executing batch files? What would be the simplest way to dynamically create new MySQL user accounts?


Thanks in advance.

- John

Posted: Tue Oct 11, 2005 12:43 am
by feyd
if you have access rights to it, the "mysql" database can be loaded, which has a table "user" where you can insert new users. However, if you do not have access to that database, then you very likely will not be able to do it without the root (or admin) level credentials.

Posted: Tue Oct 11, 2005 12:54 am
by johnhaze
Thanks feyd, I do have access to the mysql database because it's my server.

Just to clarify what you suggested, I will be able to add users by inserting new values into a "user" table in the "mysql" database?

edit: I am looking at it now, and the passwords seem to be encrypted. Is that md5 or SHA-1 encryption?

Posted: Tue Oct 11, 2005 12:58 am
by feyd
PASSWORD()

Posted: Tue Oct 11, 2005 1:38 am
by johnhaze
feyd wrote:PASSWORD()
what kind of encryption is that? can I do the same through PHP?

Posted: Tue Oct 11, 2005 1:54 am
by Weirdan
I'm familiar with creating new databases with PHP, but can I create new users as well?
http://dev.mysql.com/doc/mysql/en/grant.html

Code: Select all

mysql_query("GRANT ALL ON *.* TO '" . mysql_real_escape_string($user) . "' IDENTIFIED BY '" . mysql_real_escape_string($password) . "'");

Posted: Wed Oct 12, 2005 5:43 pm
by johnhaze
thanks, I got it to work.

but what privileges should I disable, besides GRANT?