How to create MySQL databases and users
This article was posted in: Web Hosting
This article will show you how to create a MySQL database and database user in your Krystal cPanel account. This article assumes that you are already successfully logged into cPanel.
In cPanel, click on the MySQL Databases icon in the Databases section.
Step 2 - Create a database
In the top half of the screen you will find the Create New Database and Current Databases sections.
In the Create New Database section type in the name of your new database. In the example below, we have chosen the name myshop. Click the Create Database button to create your new database.
The new database will be created. Click the Go Back button to return to the MySQL Databases page. The database will be named as follows:
So, in our example, where the cPanel account username is krystald, the full database name will become krystald_myshop.
Step 3 - Creating a database user
Before you can access your database, you must set up a dedicated MySQL user. This user is distinct and separate from your cPanel username. Looking towards the bottom of the MySQL Databases screen you will find the MySQL Users area. Here you can create MySQL users and assign them to databases. A single MySQL user may be assigned to multiple databases and multiple MySQL users may be assigned to a single MySQL database. It is quite flexible. However, in most cases, you will simply want a single user per database.
To create a MySQL user,
- enter the username in the Username: box as shown. The username has a maximum of 7 characters.
- enter a secure password or use the Password Generator function.
- click the Create User button.
The new user will be created. Click the Go Back button to return to the MySQL Databases page. The user will be named as follows:
[cPanel username]_[MySQL username]
So, in our example, where the cPanel account username is krystald, the full MySQL user name will become krystald_user1. You will notice that your new MySQL user is listed in the Current Users table at the bottom of the screen.
Step 4 - Adding a user to a database
The final step is to assign the user to a database and grant the required privileges.
- select the MySQL user from the User: drop down control.
- select the MySQL Database from the Database: drop down control.
- click the Add button.
Now we must assign the correct privileges. In almost all cases you will want to grant ALL PRIVILEGES to the user for the database concerned. To do this, simply click on the ALL PRIVILEGES check box. Then click the Make Changes button.
You will then receive a brief confirmation that the settings have been changed. Your database and database user are now ready for use.
If you are installing a web application, then you will be asked for your database name, database username and password. You will also be asked for the MySQL or Database hostname - this will always be simply localhost.