Databases: database Utility

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:

Syntax

database <command> [<database name>] [

<option_1> [<param>]

[<option_2> [<param>]]

…[<option_N> [<param>]]

]

Example

The following command line creates database DataStoreDB on a database server accessible at the IP address and port number192.168.67.78:3838 and prints the created database's Plesk ID number:

# ./database --create DataStoreDB -domain example.com -server 192.168.67.78:3838 -print-id

Commands

Command

Parameter

Description

Example

--create or -c

<database name>

Creates a database on a database server. Requires concomitant use of the -domain option. In addition, either the -type option is required if the database is to be created on a local database server or the -server option is required if the database is to be created on a remote database server.

To create database DataStoreDB on a the local MySQL server for domain example.com:

# ./database --create DataStoreDB -domain example.com -type mysql

or

# ./database -c DataStoreDB -domain example.com -type mysql

--update or -u

<database name>

Updates database settings. Adds, edits, or removes a database user.

To add user db_user to database DataStoreDB:

# ./database --update DataStoreDB -add_user db_user

or

# ./database –u DataStoreDB -add_user db_user

--remove or -r

<database name>

Deletes a database.

To delete database DataStoreDB from the database server:

# ./database --remove DataStoreDB

or

# ./database -r DataStoreDB

--remove-dbs

<id#,id#,...>

id# is the unique Plesk database ID for a database.

Deletes multiple databases from their respective databases servers.

To delete databases with with Plesk ID# 14 and ID# 56:

# ./database --remove-dbs 14,56

--remove-dbus

<id#,id#,...>

id# is the unique Plesk database ID for a database user.

Deletes multiple database users.

To delete database users with Plesk ID# 22 and ID# 34:

# ./database --remove-dbus 22,34

--help or -h

 

Displays help on the use of the utility.

To see the help info on the use of this utility:

# ./database -–help

or

# ./database –h

Options

Option

Parameter

Description

Example

-domain

<domain name>

Specifies a domain name.

Used with the --create command.

To create database DataStoreDB on domain example.com on the local MySQL server:

# ./database -c DataStoreDB -domain example.com -type mysql

-type

postgresql | mysql

 

Specifies the type of the database.

Used only with the --create command.

-passwd

<passwd>

Sets the database user password for accessing the database.

Used in conjunction with the -update_user option.

For additional comments, see the Note below the table.

To set the password to dbuserpass for user db_user to access database DataStoreDB:

# ./database -u DataStoreDB -update_user db_user -passwd dbuserpass

-passwd_type

plain | encrypted

Specifies the type of a database user password - plain or encrypted.

Set to plain by default.

Used in conjunction with the -update_user option.

For additional comments, see the Note below the table.

To set the type of the client's password to encrypted for the database user with login name db_user:

# ./database -u DataStoreDB -update_user db_user -passwd_type dbuserpass

-add_user

<database user login name>

Adds a database user to the database.

Requires concomitant use of the -passwd option.

To add the user with login name db_user to database DataStoreDB:

# ./database -u DataStoreDB -add_user db_user -passwd userpass

-update_user

<login name>

Updates database user login data.

To set the password to dbuserpass for user db_user to access database DataStoreDB:

# ./database -u DataStoreDB -update_user db_user -passwd dbuserpass

-remove_user

<user login name>

Removes a database user from the database.

To add the user with login name db_user to database DataStoreDB:

# ./database -u DataStoreDB -remove_user db_user

-user_name

<user login name>

Sets the login name for the DB user.

Used with the -update_user option.

To change the login name for the database user from db_user to db_newuser:

# ./database -u DataStoreDB -update_user db_user -user_name db_newuser

-add-access

<host name or IP address>

Adds an access record for a database user: IP address or name of a host from which a database user can remotely access the database.

Host machine may be specified by either its host name or IP address. A subnet mask can be specified, too. MySQL wildcard characters (_ and %) are allowed; for more information, consult http://dev.mysql.com/doc/refman/5.0/en/connection-access.html).

To enable remote access to database DataStoreDB from a host with IP address 192.168.67.78 for the database user db_user:

# ./database -u DataStoreDB -update_user db_user -passwd dbuserpass -add-access 192.168.67.78

-remove-access

<host name or IP address>

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.

Host machine may be specified by either its host name or IP address. A subnet mask can be specified, too. MySQL wildcard characters (_ and %) are allowed; for more information, consult http://dev.mysql.com/doc/refman/5.0/en/connection-access.html).

To disable remote access to database DataStoreDB from a host with IP address 192.168.67.78 for the database user db_user:

# ./database -u DataStoreDB -update_user db_user -passwd dbuserpass -remove-access 192.168.67.78

-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 --create command.

To create database DataStoreDB on a database server accessible at 192.168.67.78:3838 and print the database's Plesk ID number:

# ./database --create DataStoreDB -domain example.com -server 192.168.67.78:3838 -print-id

-print-id

 

Prints the created database or database user ID number.

Used only with the --create command or the -add_user option.

-charset

<charset>

Sets a character set for a PostgreSQL database to be created.

 

To create database DataStoreDB on domain example.com on the PostgreSQL server available at 192.168.67.78:3838 and set the database's charset to UTF-8:

# ./database -c DataStoreDB -domain example.com -charset UTF-8 -server 192.168.67.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 - -passwd_type options.
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 and -passwd_type options.