< All Topics

mysql/createmysqldatabase

Description

Creates a new database in an existing SPanel user account. An already existing database user can be assigned during this API call if the ‘username’ parameter is provided.

Info
If you want to create a new database and user pair, a good idea is to first create your database user by calling the mysql/createmysqluser and then run mysql/createmysqldatabase to create the new database and assign the already existing user at once.

Parameters

FieldTypeRequiredDescription
tokenstringYesAuthorizing API token – check API Basics for more information.
accountuserstringYesThe SPanel user account that is being managed or viewed.
actionstringYesThe category and function being executed.
databasestringYesThe name of the database to be created.
usernamestringNoDefault: null (empty). If specified, it must contain an existing database username which will be assigned to the newly created database.

Example

$endpointUrl = 'https://123.123.123.123/spanel/api.php';

$postData = [
  'token' => 'provided_auth_token',
  'accountuser' => 'spanelio',
  'action' => 'mysql/createmysqldatabase',
  'database' => 'db',
//'username' => 'dbuser'
];

$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $endpointUrl);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_POST, true);
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false);
$jsonOutput = curl_exec( $ch );

You can find more information about the Endpoint URL in our API Basics article.

Output

{
    "result": "success",
    "data": {
        "msg": "Database spanelio_db has been created successfully"
    }
}
Previous mysql/listdatabases
Next mysql/listusers
Table of Contents