Creating Database Users

You can create user accounts for a certain database or create universal users with access to all databases within a subscription:

  • To create a user assigned to a particular database, specify the user login name, password and the ID of the database where you want to create a user account. You can add multiple users to the database in a single packet.
  • To create a universal user, specify the user login name, password, ID of the database server and the ID of the subscription.

In this chapter:

Request Packet Structure

Response Packet Structure

Samples

 

Request Packet Structure

A request XML packet creating database user account for the database includes the add-db-user operation node:

<packet>
<database>
   <add-db-user>
   ...
   </add-db-user>
</database>
</packet>

 

The add-db-user node is presented by type DatabaseAddDBUserInputType (database_input.xsd), and its graphical representation is as follows:

CreateDbUserRPS

  • The db-id node is required. It specifies the ID of the database where a new user will be created. Data type: integer.
  • The webspace-id node is required. It specifies ID of the webspace where a new database user will be created. Used to create a universal user with access to all databases within the specified subscription. Data type: integer.
  • The db-server-id node is required. It specifies ID of the database server to which a new user will be assigned. Used to create a universal user with access to all databases within the specified database server. Data type: integer.
  • The login node is required. It specifies login name of the database user. Data type: string.
  • The password node is required. It specifies the password of the database user. Data type: string (length should be more than five digits).
  • The password-type node is optional. Specifies if it is plain or encrypted password. Data type:string. Allowed values: plain | crypt.
  • The acl node is optional. It specifies the hosts from which a database user is allowed to connect to a database. Data type:DatabaseUserAclType, which consists of host elements of the string data type.
  • The allow-access-from node is optional. It specifies the IP addresses from which access to a database is allowed. Data type:DatabaseUserRemoteAccessRulesType, which consists of ip-address elements of the string data type.
  • The role node is optional. Specifies the database user role. Data type:string. Allowed values: readWrite, readOnly, writeOnly.

Remarks

You can add multiple users to database in a single packet. Add as many add-db-user operations to the packet as the number of different users you want to create. You can also add multiple users to multiple databases in a single packet.

<database>
   <add-default-user>
   ...
   </add-default-user>
   ...
   <add-default-user>
   ...
   </add-default-user>

</database>

Important: When creating request packets, put nodes and elements in the order they follow in the packet structure.

 

Response Packet Structure

The add-db-user node of the output XML packet is presented by type DatabaseAddDBUserOutputType (database_output.xsd) and structured as follows:

  • The result node is required. It wraps the response retrieved from the server. Data type: resultType (common.xsd).
  • The status node is required. It specifies the execution status of the add-db--user operation. Data type: string. Allowed values: ok | error.
  • The errcode node is optional. Is returns the error code if the add-db--user operation fails. Data type: integer.
  • The errtext node is optional. It returns the error message if the add-db--user operation fails. Data type: string.
  • The id node is required. It specifies the database user ID. Data type: integer.

 

 

Samples

Creating a database user

This request packet creates user MyUser on the database with ID 55.

<packet>
<database>
   <add-db-user>
      <db-id>55</db-id>
      <login>MyUser</login>
      <password>hello</password>
      <role>writeOnly</role>
   </add-db-user>
</database>
</packet>

Reponse:

<packet>
<database>
   <add-db-user>
      <result>
         <status>ok</status>
         <id>132</id>
      </result>
   </add-db-user>
</database>
</packet>

 

If the database was not found, the response looks as follows:

<packet>
<database>
   <add-db-user>
      <result>
         <status>error</status>
         <errcode>1015</errcode>
         <errtext>Database not found</errtext>
      </result>
   </add-db-user>
</database>
</packet>

 

If the login name is already used by another user account on this database, the response looks as follows:

<packet>
<database>
   <add-db-user>
      <result>
         <status>error</status>
         <errcode>1007</errcode>
         <errtext>User already exists</errtext>
      </result>
   </add-db-user>
</database>
</packet> 
Creating multiple database users

This packet creates user MyUser on the databases with ID 55 and ID 57.

<packet>
<database>
   <add-db-user>
      <db-id>55</db-id>
      <login>MyUser</login>
      <password>hello</password>
   </add-db-user>

   <add-db-user>
      <db-id>55</db-id>
      <login>My2User</login>
      <password>123456</password>
   </add-db-user>

</database>
</packet> 

Reponse (if the first operation succeeded and the database with ID=57 was not found):

<packet>
<database>
   <add-db-user>
      <result>
         <status>ok</status>
         <id>132</id>
      </result>
   </add-db-user>

   <add-db-user>
      <result>
         <status>error</status>
         <errcode>1015</errcode>
         <errtext>Database not found</errtext>
      </result>
   </add-db-user>

</database>
</packet>

 

 

Leave your comments on this page

Leave your feedback or question on this documentation topic below. For technical assistance, contact your hosting service provider or submit a request to Plesk support. Suggest new features for Plesk here. Discuss general questions on the Plesk forum. All offtopic comments will be removed.