How to create a database user in cPanel via CLI using the ‘uapi’ tool?

  Uncategorized

Introduction:

UAPI (Universal API) provides a robust interface for accessing and modifying cPanel account data and settings. This API enables you to interact with various features of the cPanel interface programmatically.

Procedure:

Step 1:

Log in to your server via SSH with root.

ssh root@server-ip

Step 2:

Use the uapi command to create a new database user. Replace cpanel-username, new_user, and new_password with your specific details.

/usr/bin/uapi –user=cpanel-username Mysql create_user name=new_user password=’new_password’

For example:

/usr/bin/uapi –user=backuptest Mysql create_user name=backuptest_user password=’backuptest@123′

Step 3:

If we need to create a need database with uapi, we can use the following uapi command

/usr/bin/uapi –user=cpanel-username Mysql create_database name=database_name

For example:

/usr/bin/uapi –user=backuptest Mysql create_database name=backuptest_db

Step 4:

Grant Privileges to the User.

/usr/bin/uapi –user=cpanel-username Mysql set_privileges_on_database user=new_user database=database_name privileges=ALL PRIVILEGES

For example:

/usr/bin/uapi –user=backuptest Mysql set_privileges_on_database user=backuptest_user database=backuptest_db privileges=ALL PRIVILEGES

Conclusion:

Creating a database user via the command line in cPanel is a powerful method for managing databases efficiently, especially when automating tasks or handling multiple accounts. By following the steps outlined above, you can set up new database users and manage permissions effectively. Remember to take necessary precautions to ensure data security and integrity.

LEAVE A COMMENT