Child pages
  • UAPI Functions - Mysql::create_user
Skip to end of metadata
Go to start of metadata

Description

This function creates a MySQL® database user.

Important:

In cPanel & WHM version 76 and later, when you disable the MySQL role, the system disables this function. For more information, read our How to Use Server Profiles documentation.

Examples


 cPanel or Webmail Session URL
https://hostname.example.com:2083/cpsess##########/execute/Mysql/create_user?name=dbuser&password=12345luggage


Note:

This example calls the UAPI function via a cPanel session. For more information, read our Guide to UAPI documentation. 

 LiveAPI PHP Class
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
 
// Create a new database user.
$create_db_user = $cpanel->uapi(
    'Mysql', 'create_user',
    array(
        'name'       => 'dbuser',
        'password'   => '12345luggage',
    )
);


Note:

For more information, read our Guide to the LiveAPI System.

 LiveAPI Perl Module
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
 
# Create a new database user.
my $create_db_user = $cpliveapi->uapi(
    'Mysql', 'create_user',
    {
        'name'       => 'dbuser',
        'password'   => '12345luggage',
    }
);


Note:

For more information, read our Guide to the LiveAPI System.

 cPanel Template Toolkit
<!-- Create a new user. -->
[% execute( 'Mysql', 'create_user', { name => 'dbuser', password => '12345luggage' } ) %]


Note:

For more information, read our Guide to Template Toolkit documentation. 

 Command Line
uapi --user=username Mysql create_user name=dbuser password=12345luggage


Notes:

  • You must URI-encode values.
  • username represents your account-level username.
  • For more information and additional output options, read our Guide to UAPI documentation or run the uapi --help command. 
  • If you run CloudLinux™, you must use the full path of the uapi command:

    /usr/local/cpanel/bin/uapi


 Output (JSON)
{  
   "messages":null,
   "errors":null,
   "status":1,
   "metadata":{  

   },
   "data":null
} 


Note:

Use cPanel's API Shell interface (cPanel >> Home >> Advanced >> API Shell) to directly test cPanel API calls.

Parameters

ParameterTypeDescriptionPossible valuesExample
namestring

Required

The new user's name.

A valid database username.

Important:

To learn more about database username limits, click your database type:

 MySQL

MySQL limits the database username to 16 characters. The system includes the database prefix (the first eight characters of the cPanel account's username and an underscore character) in the character count for the username.

For example:

  • A MySQL database with the db_ prefix allows usernames that contain up to 13 characters.
  • A MySQL database with the example_ prefix allows usernames that contain up to eight characters.
 MariaDB

MariaDB limits the database username to 47 characters. The system includes the database prefix (all of the cPanel account's username and an underscore character) in the character count for the username.

For example:

  • A MariaDB database with the db_ prefix allows usernames that contain up to 44 characters.
  • A MariaDB database with the example_ prefix allows usernames that contain up to 39 characters.

dbuser
passwordstring

Required

The new user's password.

A secure password that meets the server's minimum MySQL password strength requirements.

12345luggage

Returns

This function only returns metadata.