Software Development Kit

cPanel & WHM's API [+] cPanel & WHM's API [-]


Modules and Plugins [+] Modules and Plugins [-]


cPanel & WHM Hooks [+] cPanel & WHM Hooks [-]


cPAddons (Site Software) [+] cPAddons (Site Software) [-]


System Administration [+] System Administration [-]


Developer Software [+] Developer Software [-]


Back to All Documentation



integrationblogcta.jpg

Mysql Module Documentation

The Mysql module allows you to manage MySQL Databases, users and other related settings.

The functions within this module may or may not be governed by a feature list. The required feature list may vary from function to function, to review a total list of the available features sets on a cPanel server, please see "Feature Manager" in WHM.

Mysql::number_of_dbs

API Version: 1 - Click here for documentation
Syntax: Mysql::number_of_dbs( )
Description: Retrieve the number of database users an account has created.
Returns:  
 

An integer indicating the number of MySQL users associated with the current account.


Mysql::checkdb

API Version: 1 - Click here for documentation
Syntax: Mysql::checkdb( dbname )
Description: Run a MySQL database check.
Parameters:  
  dbname (string)
  The name of the MySQL database to check.
Returns:  
 
Nothing

Mysql::deluser

API Version: 1 - Click here for documentation
Syntax: Mysql::deluser( dbuser )
Description: Remove a user from MySQL.
Parameters:  
  dbuser (string)
  The name of the MySQL user to remove. This valued must be prefixed with the cPanel username (e.g., cpuser_dbuser).
Returns:  
 
Nothing

Mysql::addhost

API Version: 1 - Click here for documentation
Syntax: Mysql::addhost( hostname )
Description: Authorize a remote host to access a cPanel account's MySQL users.
Parameters:  
  hostname (string)
  The IP address or hostname that should be provided access.
Returns:  
 
Nothing

Mysql::updateprivs

API Version: 1 - Click here for documentation
Syntax: Mysql::updateprivs( )
Description: Force an update of MySQL privileges and passwords.
Returns:  
 
Nothing

Mysql::adduser

API Version: 1 - Click here for documentation
Syntax: Mysql::adduser( username, password )
Description: Create a new MySQL user.
Parameters:  
  username (string)
  The MySQL user to create.



If database_prefix = 0 in the cpanel.config file, then the cPanel account's username will not automatically be prepended to the new MySQL username.

However, if database_prefix = 1 or the value is missing, then the username will be prepended. (For example, if you enter username then the output would be in cpuser_username.)

  password (string)
  The password for the new MySQL user.
Returns:  
 
None

Mysql::repairdb

API Version: 1 - Click here for documentation
Syntax: Mysql::repairdb( dbname )
Description: Run a MySQL database repair.
Parameters:  
  dbname (string)
  The name of the MySQL database to repair.
Returns:  
 
Nothing

Mysql::deluserdb

API Version: 1 - Click here for documentation
Syntax: Mysql::deluserdb( dbname, dbuser )
Description: Disallow a MySQL user from accessing a database.
Parameters:  
  dbname (string)
  The MySQL database from which to remove the user's permissions.
  dbuser (string)
  The name of the MySQL user to remove.
Returns:  
 
Nothing

Mysql::deldb

API Version: 1 - Click here for documentation
Syntax: Mysql::deldb( dbname )
Description: Remove a database from MySQL.
Parameters:  
  dbname (string)
  The name of the database to remove from MySQL. This value must be prefixed with the cPanel username (e.g., cpuser_dbname).
Returns:  
 
Nothing

Mysql::adduserdb

API Version: 1 - Click here for documentation
Syntax: Mysql::adduserdb( dbname, dbuser, perms_list )
Description: Grant a user permission to access a database within a cPanel account.
Parameters:  
  dbname (string)
  The name of the database to allow the user to access.
  dbuser (string)
  The MySQL user who should be given access to the database.
  perms_list (string)
  A space-separated list of permissions to grant to the user (e.g., "all" or "alter drop create delete insert update lock" ). Possible values with corresponding MySQL permissions are as follows:
alter => ALTER
temporary => CREATE TEMPORARY TABLES
routine => CREATE ROUTINE
create => CREATE
delete => DELETE
drop => DROP
select => SELECT
insert => INSERT
update => UPDATE
references => REFERENCES
index => INDEX
lock => LOCK TABLES
all => ALL

.
Returns:  
 

Nothing


Mysql::initcache

API Version: 1 - Click here for documentation
Syntax: Mysql::initcache( )
Description: Refresh the cache of MySQL information. This includes users, databases, routines and other related information.
Returns:  
 
Nothing.

Mysql::adddb

API Version: 1 - Click here for documentation
Syntax: Mysql::adddb( dbname )
Description: Add a new MySQL database to a cPanel account.
Parameters:  
  dbname (string)
  The name of the MySQL database to add.

The name of the MySQL database to add.



If database_prefix = 0 in the cpanel.config file, then the cPanel account's username will not automatically be prepended to the name of the database.

However, if database_prefix = 1 or the value is missing, then the username will be prepended. (For example, if you enter dbname then the output would be in cpuser_dbname)

Returns:  
 
Nothing

Mysql::listusersopt

API Version: 1 - Click here for documentation
Syntax: Mysql::listusersopt( )
Description: Generate a chunk of HTML for managing the MySOL users within cPanel. This function will list the users inside of
Returns:  
 
<option value="cpuser_dbuser">cpuser_dbuser</option>
<option value="cpuser_dbuser2">cpuser_dbuser2</option>

Mysql::delhost

API Version: 1 - Click here for documentation
Syntax: Mysql::delhost( host )
Description: Remove host access permissions from MySQL.
Parameters:  
  host (string)
  The IP address of the host whose access should be revoked.
Returns:  
 
Nothing

Mysql::listdbs

API Version: 1 - Click here for documentation
Syntax: Mysql::listdbs( )
Description: Generate a chunk of HTML that lists the databases for a specific page. We recommend using MysqlFE::listdbs rather than this function.
Returns:  
 
<b>cpuser_db</b><a href="deldb.html?db=cpuser_db"><img src="/frontend/x3/images/delete.jpg" border="0" alt="" /></a><a href="checkdb.html?db=cpuser_db"><img src="/frontend/x3/images/mysqlcheck.gif" border="0" alt="" /></a><a href="repairdb.html?db=cpuser_db"><img src="/frontend/x3/images/mysqlrepair.gif" border="0" alt="" /></a><blockquote><u>Users in db</u><br />
cpuser_dbuser (Privileges: SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, CREATE ROUTINE) <a href="deluserfromdb.html?db=cpuser_db&user=cpuser_dbuser"><img src="/frontend/x3/images/delete.jpg" border=0></a>
<br />
<blockquote>
<table>
<tr>
<td colspan=2><b>Connection Strings</b></td>
</tr>
<tr>
<td><b>Perl</b></td>
<td><i><font size=-1>$dbh = DBI->connect("DBI:mysql:cpuser_db:localhost",<br />"cpuser_dbuser","&lt;PASSWORD HERE&gt;");</i></font></td>
</tr>
<tr>
<td><b>PHP</b></td>
<td><i><font size=-1>$dbh=mysql_connect ("localhost", "cpuser_dbuser",<br />"&lt;PASSWORD HERE&gt;") or die('Cannot connect to the database because: ' . mysql_error());<br />mysql_select_db ("cpuser_db");</font></i></td>
</tr>
</table>
</blockquote>
</blockquote><br /><b>cpuser_db2</b><a href="deldb.html?db=cpuser_db2"><img src="/frontend/x3/images/delete.jpg" border="0" alt="" /></a><a href="checkdb.html?db=cpuser_db2"><img src="/frontend/x3/images/mysqlcheck.gif" border="0" alt="" /></a><a href="repairdb.html?db=cpuser_db2"><img src="/frontend/x3/images/mysqlrepair.gif" border="0" alt="" /></a></blockquote><br />

Mysql::routines

API Version: 1 - Click here for documentation
Syntax: Mysql::routines( )
Description: List MySQL routines created by a user.
Returns:  
 
This function returns HTML similar to:

If <span class=\"status\">USERNAME</span> is deleted then these routines will be unusable: <span class=\"status\">routine1, routine2</span><br/>"

Mysql::gethost

API Version: 1 - Click here for documentation
Syntax: Mysql::gethost( )
Description: Get the address of the MySQL host that is used by the server.
Returns:  
 
The IP or hostname of the MySQL host being used.

Mysql::number_of_dbs

API Version: 1 - Click here for documentation
Syntax: Mysql::number_of_dbs( )
Description: Retrieve the number of databases currently in use.
Returns:  
 
An integer indicating the number of databases in use by a user.

Mysql::listdbsopt

API Version: 1 - Click here for documentation
Syntax: Mysql::listdbsopt( )
Description: Generate a list of databases associated with a cPanel account, encapsulated in >option< HTML tags. We recommend using MysqlFE::listdbs rather than this function.
Returns:  
 
<option value="cpuser_db">cpuser_db</option>
<option value="cpuser_db2">cpuser_db2</option>

Mysql::listusers

API Version: 1 - Click here for documentation
Syntax: Mysql::listusers( )
Description: Generate a chunk of HTML for managing MySQL users. We recommend using MysqlFE::listusers rather than this function.
Returns:  
 
cptest_dbuser <a href="deluser.html?user=cptest_dbuser"><img src="/frontend/x3/images/delete.jpg" border="0" alt="" /></a><br />
cptest_dbuser2 <a href="deluser.html?user=cptest_dbuser2"><img src="/frontend/x3/images/delete.jpg" border="0" alt="" /></a><br />

Topic revision: r4 - 06 Nov 2012 - 18:00:39 - Main.LaurenceSimon