How to Add a User to a Database and Grant Privileges Print

  • 0

Updated guide: This article has been refreshed for current hosting environments. Control-panel labels and available features can vary slightly by account, server configuration, or software version, but the workflow below follows the current approach used on modern hosting platforms. This guide is written to help you complete How to Add a User to a Database and Grant Privileges safely and understand what to check if the expected result does not appear.

Before you begin

  • Confirm the database name and username before changing configuration files.
  • Create a backup before importing, deleting or modifying tables.
  • Use the correct database user privileges for the application.
  • For large databases, check the hosting limits before starting an import.

Database naming and permissions

On many cPanel servers, database names and users are prefixed with the hosting account username. An application configuration file may therefore contain a name such as cpuser_app rather than simply app. The database user must also be assigned to the database with the required privileges. A correct database name with the wrong user privileges will still result in connection or permission errors.

Before importing an SQL file

  • Check the file size and the available database/import limits.
  • Make sure the target database is the intended database.
  • If replacing an existing database, take a fresh backup first.
  • For very large imports, ask support whether command-line or server-side import is available.

Database troubleshooting

  • Access denied: Check the database username, password, database name and user privileges. In cPanel, make sure the user is assigned to the database with the required privileges.
  • Connection failed: Confirm the application is using the correct database host. Many shared-hosting applications use localhost, but this can vary by server configuration.
  • Import fails: Check the SQL file size, PHP upload limits and database limits. For large imports, a command-line or provider-assisted import may be more appropriate.
  • Site broke after an import: Do not repeatedly import the same dump. First determine whether the application tables, database prefix, character set or configuration file were affected.

When to contact support

Contact support when the required feature is unavailable, a server-level service is failing, an account is locked, a restore requires privileges you do not have, or you have verified the settings but the service still does not work. When contacting support, include the domain name, the exact error message, what you changed, when the issue started, and screenshots or log output where appropriate. Do not send passwords or other authentication secrets.

Original illustrated procedure

1. Log in to your cPanel account.

2. In the Databases section, click on MySQL Databases.
 

3. Scroll down to the end of the page and under Add User to Database. Select a user from the drop-down list, and choose a Database from the list.

4. Click on Add.


5. On Manage User Privileges. Mark the box ALL PRIVILEGES and click on Make Changes.


Was this answer helpful?

« Back