MySQL Databases

From HelioHost Wiki
Jump to: navigation, search

MySQL is a very handy tool available to webmasters who want to take advantage of dynamic webpages which run on languages such as PHP, as well as softwares like WordPress that may have been manually installed (not installed using Softaculous).

More information about MySQL can be found at Wikipedia and official website

Contents

Creating a database

Before you take advantage of MySQL, you will need to create a database and a user to work with. To access the MySQL Databases section of cPanel, use the button available on the homepage.

Step 1: Creating the database

In the MySQL Databases section of cPanel, take a look at the 'Create new database' section of the resulting page. Give your database a name and submit the form. In the resulting page, you should see your new database in the list of databases.

Step 2: Creating the user

Now scroll down to the 'Create new user' section of the resulting page. Fill in a username and password (a strong password is always good) and submit the form. In the resulting page, you should see your new user in the list of users right at the bottom of the page.

Step 3: Assign the user to the database

In the 'Add user to database' section of the resulting page, select your newly created user and your newly created database from the drop down, then submit the form. In the resulting page, give the user the appropriate privileges (the commands the user can run). If you are unsure, just click 'All privileges'. Then submit the form. In the resulting page, in the list of databases, you should see your newly created user in 'Users' column alongside your newly created database.

Accessing the database

Your database details

If you are connecting locally, then your 'HOST' is 'localhost'. Your database name is the name you specified, but prefixed with your cPanel username and then an underscore (ex. CPANEL_DATABASE).

Managing the database with phpMyAdmin

By using the phpMyAdmin button on cPanel's homepage, you can control and manage your databases and issue commands. More information about phpMyAdmin is available at the official site.

Connecting to the database through PHP

Create a blank PHP file, enter:

<?php
$mysqli = new mysqli("HOST", "USERNAME", "PASSWORD", "DATABASE");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error()); //this will print out the error while connecting to MySQL, if any
exit();
}
?>

To execute a query via PHP:

<?php
$mysqli = new mysqli("localhost", "USERNAME", "PASSWORD", "DATABASE");
$sql="SELECT * FROM `TABLE`";
$result = mysqli_query($mysqli,$sql);
?>

Filling in your USERNAME, PASSWORD, and DATABASE with the actual information (as above).

Connecting Remotely

Step 1: Login to your cpanel

Go to your cpanel.

Step 2: Click on remote Mysql

Click remote MySQL

Step 3: Adjust Settings

Put a percent sign(%) for all IP or else enter the IP to give access to only that particular IP in the box and click submit.

Step 4: Connect

Use the host stevie.heliohost.org or johnny.heliohost.org

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox
Google AdSense