1

I'm trying to auto create a database/user and grant privelges for a specific domain that was created within Plesk.

The trouble I'm having is I want the database to still be available if you access that user via Plesk control panel.

Here's what I have:

$con = mysql_connect("127.0.0.1","root","pass");
mysql_query("CREATE DATABASE ".$db."",$con)or die(mysql_error());
mysql_query("GRANT ALL ON ".$db.".* to  ".$user." identified by '".$dbpass."'",$con) or die(mysql_error());

This will work, but it won't show up in Plesk for the domain I'd like it to. How do I tie this database to a specific domain within plesk?

Thank you!

dzm
  • 22,844
  • 47
  • 146
  • 226

1 Answers1

4

I see this question is super old, but I was wondering the same thing, and found a command line tool built into Plesk 10.x that allows you to do exactly what you need.

Create database

/usr/local/psa/bin/database --create new_database_name -domain the_domain_in_question.com -print-id -server localhost -type mysql

To create a new user for a database:

/usr/local/psa/bin/database --update new_database_name -add_user new_username -passwd new_password

The examples create a new MySQL database called "new_database_name" for the domain "the_domain_in_question.com" and then adds a new user called "new_username" with the password “new_password”

You just need get PHP to execute that. Here's an article with some info about that. I'll be testing this out next.

Community
  • 1
  • 1
Milo
  • 297
  • 3
  • 13