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
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 |
---|---|---|---|
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
Deletes multiple database users. Parameter |
To delete database users whose Plesk ID are 22 and 34: plesk bin database --remove-dbus 22,34 |
|
|
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
|
|
|
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 |
|
|
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 |
|
|
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 |
---|---|---|---|
|
|
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 |
|
|
Specifies the type of the database. Used only with the |
|
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
Sets the database user's role. Is used with the |
To set the role of the JDoe user to "read only":
plesk bin database |
|
|
Sets the database to which a database user will have access. Is used with the |
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
|
|
|
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 |
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
|
|
|
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
|
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|||
|
|
Prints the created database or database user ID number. Used only with the |
|
|
|
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 |
|
|
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 |
|
|
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.