database: Databases
The database
utility is used to manage databases and database users
in Plesk through CLI. By using this utility, you can perform the
following tasks:
- creating or deleting databases
- adding and removing database users
- adding or removing access control records for MySQL database users
- adding firewall access rules for PostgreSQL database users
- editing database user credentials
- setting charset for PostgreSQL databases
Usage
database <command> [<database name>] [
<option_1> [<param>]
[<option_2> [<param>]]
... [<option_N> [<param>]]
]
Example
The following command creates database jdoe-gallery on a database server accessible at the IP address and port number 192.0.2.78:3838 and displays the ID of the created database:
plesk bin database --create jdoe-gallery -domain example.com -server 192.0.2.78:3838 -print-id
Commands
Command | Parameter | Description | Example |
---|---|---|---|
--create or -c
|
<database_name> |
Creates a database on a database server. Requires the In addition, either the |
To create the database jdoe-gallery for the domain example.com on the local MySQL server: plesk bin database --create jdoe-gallery -domain example.com -type mysql or plesk bin database -c jdoe-gallery -domain example.com -type mysql |
--update or -u
|
<database_name> |
Updates database settings. Adds, edits, or removes a database user. |
To add the user Jane to the database jdoe-gallery: plesk bin database --update jdoe-gallery -add_user Jane or plesk bin database -u jdoe-gallery -add_user Jane |
--remove or -r
|
<database_name> |
Deletes a database. |
To delete database jdoe-gallery from the database server: plesk bin database --remove jdoe-gallery or plesk bin database -r jdoe-gallery |
--register |
<database_name> |
Registers a database in Plesk and assigns it to a domain. |
To register the database sampledb found on the local MySQL server in Plesk and assign it to the domain example.com: plesk bin database --register sampledb -domain example.com -server localhost:3306 |
--assign-to-subscription |
<database_name> |
Assigns the database to a subscription. |
To assign the database jdoe-gallery to the subscription owning the domain example.com: plesk bin database --assign-to-subscription jdoe-gallery -domain example.com -server localhost:3306 |
--remove-dbs |
<ID,ID,...> |
Deletes multiple databases specified with their ID from respective databases servers. Parameter |
To delete databases which Plesk ID are 14 and 56: plesk bin database --remove-dbs 14,56 |
--remove-dbus |
<ID,ID,...> |
Deletes multiple database users. Parameter |
To delete database users whose Plesk ID are 22 and 34: plesk bin database --remove-dbus 22,34 |
--create-dbuser |
<login> |
Creates a database user with the specified name. Requires
We recommend that you use this command instead of
|
To create the database user John with the password mypassword for the database mydb on the domain example.com: plesk bin database --create-dbuser John -passwd mypassword -domain example.com -server localhost:3306 -database mydb |
--update-dbuser |
<login> |
Updates a database user with the specified name. Requires the We recommend that you use this command instead of
|
To update the password for the database user John: plesk bin database --update-dbuser John -passwd newpassword -server localhost:3306 |
--remove-dbuser |
<login> |
Removes a database user with the specified name. We recommend that you use this command instead of
|
To remove the universal database user John with the password mypassword on the domain example.com: plesk bin database --remove-dbuser John -server localhost:3306 |
--register-dbuser |
<login> |
Registers a database user in Plesk and assigns it to a database. |
To register the database user dbuser found on the local MySQL server in Plesk, assign it to the database sampledb belonging to the domain example.com, grant the user the Read and Write permissions, and set the user’s password to dbpass: plesk bin database --register-dbuser dbuser -domain example.com -database sampledb -type mysql -user-role readWrite -passwd dbpass |
--help or -h
|
Displays help on the use of the utility. |
To view the help info on the use of this utility: plesk bin database --help or plesk bin database -h |
Options
Option | Parameter | Description | Example |
---|---|---|---|
-domain |
<domain_name> |
Specifies a domain name. Required with |
To create database jdoe-gallery for the domain example.com on the local MySQL server: plesk bin database -c jdoe-gallery -domain example.com -type mysql |
-type |
postgresql|mysql |
Specifies the type of the database. Used only with the |
|
-passwd |
<password> |
Sets the database user password for accessing the database. Is required with For additional comments, see the Note below the table. |
To set the password to access database jdoe-gallery for the user with the login name JDoe to sample: plesk bin database -u jdoe-gallery -update_user JDoe -passwd sample |
-add_user |
<database_user_login> |
Adds a database user to the database. Requires |
To add the user with the login name JDoe and password sample to database jdoe-gallery: plesk bin database -u jdoe-gallery -add_user JDoe -passwd sample |
-update_user |
<login> |
Updates database user settings. |
To set the password for user with the login name JDoe to access database jdoe-gallery to sample: plesk bin database -u jdoe-gallery -update_user JDoe -passwd sample |
-remove_user |
<login> |
Removes a database user from the database. |
To remove the user with the login name JDoe from the database jdoe-gallery: plesk bin database -u jdoe-gallery -remove_user JDoe |
-user_name |
<login> |
Sets a login for a database user. |
To change the jdoe-gallery user login from JDoe to Jane: plesk bin database -u jdoe-gallery -update_user JDoe -user_name Jane |
-user-role |
readWrite|readOnly|writeOnly |
Sets the database user’s role. Is used with the
--create-dbuser and the --update-dbuser commands. |
To set the role of the JDoe user to “read only”: plesk bin database --update-dbuser JDoe -user-role readOnly |
-database |
<name> |
Sets the database to which a database user will have access. Is
used with the --create-dbuser and --update-dbuser
commands, but is not obligatory because you can create a user
and not assign it to a database. |
To create the database user John with the password mypassword for the database mydb on the domain example.com: plesk bin database --create-dbuser John -passwd mypassword -domain example.com -server localhost:3306 -database mydb |
-any-database |
Grants a database user access to all databases within the
corresponding hosting account, thus making this user a
universal database user. Is used with the --create-dbuser
and --update-dbuser commands. |
To create the database user John with the password mypassword and with access to all databases within the domain example.com: plesk bin database --create-dbuser John -passwd mypassword -domain example.com -server localhost:3306 -any-database |
|
-allow-access-from |
<IP address 1, IP address 2, ...> |
Allows remote connections to the database from the specified IP addresses. The addresses are added to firewall rules. It works for database users of local PostgreSQL. |
To allow access to the PostgreSQL database jdoe-gallery from IP address 192.0.2.78: # plesk bin database -u jdoe-gallery -allow-access-from 192.0.2.78 |
-add-access |
<host> |
Adds an access record for a database user: IP address or name of a host from which a database user can remotely access a MySQL database. The MySQL database can be local or remote. This option adds a new record to the existing MySQL ACL (access
control list). To replace the entire list with a new list, use
the Host can be specified by either its host name or IP address. A
subnet mask can be specified, too. MySQL wildcard characters
( |
To enable remote access to the database jdoe-gallery from the host with IP address 192.0.2.78 for the database user Jane: plesk bin database -u jdoe-gallery -update_user Jane -passwd sample -add-access 192.0.2.78 |
-remove-access |
<host> |
Removes an access record for a database user: IP address or name of a host from which a database user can remotely access the database. This option removes a record from an existing MySQL ACL (access control list). Host can be specified by either its host name or IP address. A
subnet mask can be specified, too. MySQL wildcard characters
( |
To disable remote access to database jdoe-gallery from the host with IP address 192.0.2.78 for the database user Jane: plesk bin database -u jdoe-gallery -update_user Jane -passwd sample -remove-access 192.0.2.78 |
-set-acl |
<host 1, host 2, ..., host n> |
Sets up the MySQL access control list (ACL) for the specified database user, for example, on order to enable remote access to the database on behalf of this user. The MySQL database can be local or remote. This option replaces an existing ACL with the specified one. Host can be specified by either its host name or IP address. A
subnet mask can be specified, too. MySQL wildcard characters
( |
To enable remote access to the MySQL database jdoe-gallery from remote hosts with IP address 192.0.2.78 and 192.0.2.79 for the database user with the name Jane: plesk bin database -u jdoe-gallery -update_user Jane -set-acl 192.0.2.78, 192.0.2.79 |
-set-privileges |
<name,name,...> |
Adds one or more privileges to the specified database user on the specified database. Used with the Available privileges are: Also sets global privileges for the specified database user on all the databases on the hosting account. Available global privileges are: |
To add the plesk bin database --update-dbuser JDoe -set-privileges Select -database jdoe-gallery -server localhost:3306 |
-server |
host[:port] |
Specifies the host name or IP address and port number for the machine on which a database server is hosted. Used only with the |
To create database jdoe-gallery for the domain example.com on the database server accessible at 192.0.2.78:3838 and print the Plesk database ID: plesk bin database --create jdoe-gallery -domain example.com -server 192.0.2.78:3838 -print-id |
-default |
Makes the specified user the default user for the specified database. Used with the |
To make the user JDoe the default user for the database jdoe-gallery hosted on the local MySQL server: plesk bin database --update-dbuser JDoe -default -database jdoe-gallery -server localhost:3306 |
|
-collation |
<collation name> |
Sets the collation for the specified database. |
To set the collation for the database jdoe-gallery to utf8_general_ci: plesk bin database -u jdoe-gallery -collation utf8_general_ci |
-charset |
<charset> |
Specifies a character set for a PostgreSQL database to be created. |
To create database jdoe-gallery for the domain example.com on the PostgreSQL server available at 192.0.2.78:3838 and set the database’s charset to UTF-8: plesk bin database -c jdoe-gallery -domain example.com -charset UTF-8 -server 192.0.2.78:3838 |
Note: Use of this option is not recommended. Passing passwords through CLI
as parameters of the -passwd
option may potentially compromise
the system’s security as command line can be observed by other users
of the system. It is more secure to pass passwords through the
environment variables. You can transfer non-encrypted passwords by
using environment variable PSA_PASSWORD
while using single quotes
to specify the empty values in the command line for the argument of
the -passwd
option.
Similarly, you can transfer encrypted passwords through the
environment variable PSA_CRYPTED_PASSWORD
while using single
quotes to specify the empty values in the command line for the
argument of the -passwd
option.