# Managing MySQL databases and users

> Create MySQL databases and users in cPanel, assign privileges, change passwords, and repair or delete databases.

Source: https://helpcenter.ruachost.com/cpanel/databases/managing-mysql-databases-and-users/

cPanel provides tools to create, manage, and delete MySQL databases and users. You can also assign privileges, repair databases, and revoke access when needed.

## Managing Database Users

### 1. Creating a Database User

1. Log in to **cPanel**.
2. Go to **Databases → MySQL Databases** (or **Manage My Databases** in newer versions).
3. Under **Add New User**:

   - Enter a **username**.
   - Enter and confirm a **password** (or use the **Password Generator**).
4. Click **Create User**.

### 2. Changing a User’s Password

1. In **MySQL Databases**, under **Current Users**, locate the user.
2. Click **Change Password**.
3. Enter the new password → **Change Password**.

### 3. Renaming a User

1. In **Current Users**, locate the user.
2. Click **Rename**.
3. Enter the new name → **Proceed**.

### 4. Deleting a User

1. In **Current Users**, locate the user.
2. Click **Delete** → confirm.  Deleting a user also removes all their database permissions.

## Managing Databases

### 1. Creating a Database

1. In **MySQL Databases**, under **Create New Database**, enter a name.
2. Click **Create Database**.  Note: cPanel prefixes your account username to the database name (e.g., `user_dbname`).

### 2. Adding a User to a Database

1. In **MySQL Databases**, under **Add User to Database**:

   - Select the **user**.
   - Select the **database**.
2. Click **Add**.
3. Assign privileges (or select **ALL PRIVILEGES**) → **Make Changes**.

### 3. Checking and Repairing a Database

1. In **MySQL Databases**, under **Modify Databases**:

   - Select the database from **Check Database** → **Check Database**.
   - If errors are found, select it under **Repair Database** → **Repair Database**.

### 4. Revoking User Privileges

1. In **Current Databases**, locate the user attached to a database.
2. Click the **trash can icon** → **Revoke User Privileges from Database**.

### 5. Deleting a Database

1. In **Current Databases**, locate the database.
2. Click **Delete** → confirm.  Note: Deleting a database does not delete its users, but it revokes their privileges.
