How to Setup MySQL Database in cPanel

Today we will learn how to setup mysql database in cPanel. Increasingly in these days information is a precious commodity. As such we need a place to store this information. Whether this information is confidential or not, or even a “shopping list”.

 

Setup MySql Database

1. Access to your cPanel Main Page

And Select “MySQL Database Wizard

mysql panel

2. Name your Database

Name your database and click “Next Step“.

setup mysql database

3. Set UserName and Password

Choose the username and the password to your database. This is necessary to later we connect to database. And click “Create User“.

create database user

4. Set User Privileges

Now we need to setup the user privileges, this depend what you are going to do. I will check “All PRIVILEGES“. And click “Next Step“.

cpanel database

Now the database is created. Now we will connect to database using PHP.

5. Connect to Database

To connect to database we need:

  • Server Name:
    • you can find it in “General Information“, and click in “Server Information“:
    • And then search for “Server Nameserver name cpanel
  • DataBase Username;
  • Database Password.

 

Writing our php file to connect to database:

If we want connect to our database we only need write some code:

<?php
    //your server name
    $servername = "cpanel";
    //the database username that you have created
    $username = "w7code_mydatabase";
    //the database password that you have choosen
    $password = "12345678";
    //the database name that you have choosen
    $dbname = "w7code_mydatabase";
    //establishing the database connection using mysqli_function
    $db = mysqli_connect($servername, $username, $password, $dbname);

// Check connection i
if ($db->connect_error) {
    die("Connection failed!");
}

 

 

And this is how we setup database mysql in cPanel.

Do you have any doubt? Feel free to comment bellow your doubt!

 

 


Leave a Reply

Your email address will not be published. Required fields are marked *