Hi friends,
I want to create new database in cpanel.I am trying to create new database in cpanel but after adding new database in cpanel as per below mysql query :
create database demo_test
It creates database but I am unable to access database.So for that I am doing something wrong while creating new database in cpanel.
Please any one give me step by step tutorial or guidance for creating new database in cpanel.
Thank You
Hi,
You are not able to access database because you are creating new database in cpanel by sql query which is not right way on server or cpanel because you have to create new user for database and assign that user to newly created database in cpanel.
To make available newly created or added database in cpanel/hosting.I am giving you step by step tutorial to create new database in cpanel and then how we can access database from our php code.
Step 1: Open your cpanel by entering your domain url as http://example.com:2082 or http://example.com/cpanel .
Now enter your user name and password for website .
Step 2 :- Now long list will come with different functionality. You have to
Go to >> Databases >> Mysql Database Wizart
Step 3 :- Not it will open new page for creating new database.It will ask for name of new database that you want to create.
Step 4 :- Click on “Next step”.As on previous Image.
On this new screen you have to enter credential details of users for database like username & password.
Now click on “Create User” (Note:Please don’t forget to take copy of your password)
Step 5 :- Now you will see page or privileges for user who will belong to database of cpanel .Privileges means different rights to user for database.User can perform and access only operation that has been given from here.
Step 6 : As I want to give all the privileges to user then I will select all the options or I will click on ”ALL PRIVILEGS”.Then it will be selected automatically. Then I will click on “Next Step”.
Step 7:Conguraulations !! successfully you have created new database in cpanel.It will give below screen for success message.Now you have to just access this database from php code.
Step 8: Please run below code to check for access of database and check connection with database.
<?php
$host=”localhost”;
$db_user=”selfioex_dbdemo”;
$db_pass=”password”;
$db_name=”selfioex_dbdemo”;
$con = mysqli_connect($host, $db_user, $db_pass, $db_name);
// Check connection
if (mysqli_connect_errno())
{
echo “Failed to connect to MySQL: ” . mysqli_connect_error();
}
else{
echo ‘You have established connection successfully’;
}
?>