Advertisement
Tech

Create a MySQL Database using phpmyadmin, php, cpanel ,etc...

If you plan on building a dynamic website, chances are you’ll need some sort of database system to hold the data for the website. MySQL is one of the most popular database systems out today and it’s free. This article will show you how to create a MySQL database.

By Strobe
Desk Tech
Reading time 3 min read
Word count 439
Web development Internet Beginners tutorials
Create a MySQL Database using phpmyadmin, php, cpanel ,etc...
Advertisement
Quick Take

If you plan on building a dynamic website, chances are you’ll need some sort of database system to hold the data for the website. MySQL is one of the most popular database systems out today and it’s free. This article will show you how to create a MySQL database.

On this page

There are several ways to create a MySQL database. The most common way to create MySQL database is to use the functions located in your cpanel. Alternative ways exist such as interfacing with the MySQL database itself or using third party programs such as phpMyAdmin. You could even create a MySQL database using a programming language such as PHP. Each of the following can be used to create a MySQL database.

Using a database client to create a MySQL database

Advertisement

To create a MySQL database using a database client, log into your server and when you get to the command prompt, type the following:

CREATE DATABASE dbname

Advertisement

dbname is the name of the database you would like to create. If the database is created correctly, you’ll receive a confirmation message. Once the database is created, you can add tables as follows:

CREATE TABLE tablename

Advertisement

(

myid INT(4),

Advertisement

myname VARCHAR(255),

myusername VARCHAR(255)

Advertisement

)

This query would create a MySQL database named tablename with the following fields: myid, myname, and myusername. INT and VARCHAR are the column types and the type of data these columns will hold.

Advertisement

To create a MySQL database using cPanel

Log into your cpanel and select the “MySQL Databases” link. First you’ll want to create the database by entering the name of the new database. Then simply click the “Create Database” button. You’ve just created a new database.

Advertisement

To create a MySQL database using PHP

Many PHP programs install a database on their first run. If you need to create a MySQL database using code, you’ll need to use the following code:

Advertisement

The first line after the opening tag is just the connection to the database. The format for mysql_connect function is host, user, and pass. The next line in our PHP script starts with an if statement. The if statement just checks to see of the mysql_create_db function returns true. If the function returns true and creates the MySQL database “database_name” ok, then “Database Created!” is printed to the screen. Otherwise, we get the error message.

You can also create a MySQL database using phpMyAdmin

Advertisement

Once logged into phpMyAdmin, you’ll see a link that allows you to create a new database. Once you’ve entered all the information click create database and you’re all set. Once the MySQL database is created, it will be shown on the left pane of phpMyAdmin.

There are other third party programs that can create a MySQL database, the choice to which one you use is totally up to you.

Advertisement
Keep Exploring

More from Tech

Filed under
Web development Internet
More topics
Beginners tutorials
Advertisement