This article describes how to create a MySQL database.
Use mysqladmin to create a database:
Special permissions are required to create or delete a MySQL database. Therefore, if you access the database as a root user, you can create any database using the mysql mysqladmin binary.
Example:
Here is a simple example to create a database named TUTORIALS:
[root@host]# mysqladmin -u root -p create TUTORIALSEnter password:******
This creates a database: TUTORIALS.
Use a PHP script to create a database:
PHP uses the mysql_query function to create or delete a MySQL database. This function has two parameters. if TRUE is returned, success or failure is returned, FALSE is returned.
Syntax:
bool mysql_query( sql, connection );
Example:
Try the following example to create a database:
Creating MySQL Database -by www.bitsCN.com<?php$dbhost = 'localhost:3036';$dbuser = 'root';$dbpass = 'rootpassword';$conn = mysql_connect($dbhost, $dbuser, $dbpass);if(! $conn ){ die('Could not connect: ' . mysql_error());}echo 'Connected successfully
';$sql = 'CREATE DATABASE TUTORIALS';$retval = mysql_query( $sql, $conn );if(! $retval ){ die('Could not create database: ' . mysql_error());}echo "Database TUTORIALS created successfully\n";mysql_close($conn);?>