{"id":651,"date":"2021-06-05T16:42:51","date_gmt":"2021-06-05T11:12:51","guid":{"rendered":"https:\/\/mediastroke.com\/blog\/?p=651"},"modified":"2022-07-01T13:17:25","modified_gmt":"2022-07-01T07:47:25","slug":"php-mysql-connection","status":"publish","type":"post","link":"https:\/\/mediastroke.com\/blog\/php-mysql-connection\/","title":{"rendered":"PHP MySQL Connection Using cPanel Hosting"},"content":{"rendered":"\n

Guide for PHP MySQL Connection Setup Under cPanel <\/h1>\n\n\n\n

PHP MySQL connection setting up on a cPanel hosting is generally challenging for beginners. To make things simple, we have created this guide, which offers a detailed overview of how to set up a MySQL database and connect it to a PHP application using cPanel hosting. This article also explains about how to deploy a local project (running on XAMPP, LAMP, WAMP, etc.) in cPanel Hosting.<\/p>\n\n\n\n

To make your PHP project with MySQL live, just follow below simple steps.<\/p>\n\n\n\n

How to Setup MySQL Database in cPanel?<\/h2>\n\n\n\n

To setup MySQL database in cPanel, basically you need to create MySQL Database, create MySQL User, assign User to Database & manage User Privileges and import database using .sql file. Steps for the same are explained in below sections:<\/p>\n\n\n\n

Create MySQL database in cPanel:<\/h3>\n\n\n\n
  1. Start by logging into cPanel and selecting the MySQL databases<\/strong> option under the Databases<\/strong> section.<\/li>
  2. Enter the appropriate database name in the text field next to Create New Database<\/strong> (for example, username_test) and press the Create Database<\/strong> button.<\/li><\/ol>\n\n\n\n

    Creating User to access MySQL Database:<\/h3>\n\n\n\n

    You have to create a MySQL User and give the necessary privileges, before they may access and control the database.<\/p>\n\n\n\n

    1. To create the MySQL User, Enter the appropriate user’s name in the text field next to MySQL Users >> Add New<\/strong> User<\/strong> and set a password for the new user.<\/li>
    2. It is highly recommended to use the Password Generator<\/strong> to create strong password. Use it by clicking create a secure password.<\/li><\/ol>\n\n\n\n

      Note:<\/strong> Remember to save the database name, username, and password to use in PHP programs to connect to the database.<\/p>\n\n\n\n

      Assign User to MySQL Database:<\/h3>\n\n\n\n

      Now as we have both a MySQL Database and a MySQL User, we must assign the MySQL User to the Database in order to set the appropriate privileges. To do this, follow the below steps:<\/p>\n\n\n\n

      1. Select Add User To Database<\/strong> under the Database<\/strong> section. Make sure you select the appropriate Database and User before proceeding. Once confirmed, simply click the Add<\/strong> button.<\/li>
      2. You have to assign the appropriate privileges to the MySQL User in the next screen. Here, we simply select the All Privileges<\/strong> option to give users full access to our MySQL database so they may manage it without any limitations and click the Make Changes<\/strong> button.<\/li><\/ol>\n\n\n\n
        \"Php<\/figure>\n\n\n\n

        NOTE:<\/strong> You can assign multiple MySQL Users with different sets of privileges to the same MySQL database.<\/p>\n\n\n\n

        Import Database to cPanel:<\/h3>\n\n\n\n
        1. Using phpMyAdmin in XAMPP or LAMP, export the local database to a .sql<\/strong> or .sql.gz<\/strong> file to import it into cPanel.<\/li>
        2. Then, select Databases >> phpMyAdmin<\/strong> option under cPanel. On the phpMyAdmin page, select your database and click Import<\/strong>. The next window will provide you the option to browse and upload SQL script to the server.<\/li><\/ol>\n\n\n\n
          \"import<\/figure>\n\n\n\n