MySQL-Creation of Database

creation of database in my sql

MySQL-Creation of Database : A database is used to store the collection of records in an organized form. It allows us to hold the data into tables, rows, columns, and indexes to find the relevant information frequently. We can access and manage the records through the database very easily.

MySQL-Creation of Database Example

Here is a simple example to create a database called TUTORIALS −

[root@host]# mysqladmin -u root -p create TUTORIALS

Enter password:******

This will create a MySQL database called TUTORIALS.

MySQL-Creation of Database using PHP Script

PHP uses mysql_query function to create or delete a MySQL database. This function takes two parameters and returns TRUE on success or FALSE on failure.


bool mysql_query( sql, connection );

Parameter & Description

  • sql : Required – SQL query to create or delete a MySQL database
  • connection : Optional – if not specified, then the last opened connection by mysql_connect will be used.


The following example to create a database −



      <title>Creating MySQL Database</title>





         $dbhost = 'localhost:3036';

         $dbuser = 'root';

         $dbpass = 'rootpassword';

         $conn = mysql_connect($dbhost, $dbuser, $dbpass);


         if(! $conn ) {

            die('Could not connect: ' . mysql_error());


         echo 'Connected successfully<br />';


         $retval = mysql_query( $sql, $conn );


         if(! $retval ) {

            die('Could not create database: ' . mysql_error());


         echo "Database TUTORIALS created successfully\n";





Spread the love

Leave a Comment

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