Wu Yuxiong - natural born MySQL study notes: MySQL create database

After landing MySQL service, to create a database using the create command syntax is as follows: 
the CREATE DATABASE database name; 
command simply demonstrates the creation of the database, the data called RUNOOB: 
[root @ Host] # MySQL -u root -p    
the Enter password : ******   # after logging into the terminal 

MySQL > the create dATABASE RUNOOB; 

use mysqladmin create a database 
using a regular user, you may need special permissions to create or delete MySQL database. 

Here logged in as root, root user has the highest authority, you can use mysql mysqladmin command to create the database. 
The following command demonstrates the process of creating a simple database, data called RUNOOB: 
[root @ Host] # mysqladmin -u root -p the Create RUNOOB 
the Enter password: ****** 
After the successful implementation of the above command will create the MySQL database RUNOOB.
Create a database using PHP script 
PHP using mysqli_query function to create or delete MySQL database. 
This function takes two arguments and returns TRUE if executed successfully, otherwise it returns FALSE. 
Syntax 
mysqli_query (connection, query, resultmode) ;

 

 

The following example demonstrates the use PHP to create a database:
 < PHP? 
$ Dbhost = ' localhost: 3306 ' ; // MySQL server host address 
$ dbuser = ' root ' ; // MySQL username 
$ dbpass = ' 123456 ' ; // mysql username and password 
$ Conn = mysqli_connect ($ dbHost, dbuser $, $ dbpass);
 IF ($ Conn!) 
{ 
  Die ( ' connection error: ' . mysqli_error ($ Conn)); 
} 
echo ' successful connection <br /> ' ; 
$ SQL =' The CREATE DATABASE RUNOOB ' ; 
$ retval = the mysqli_query ($ Conn, $ SQL);
 IF ($ retval!) 
{ 
    Die ( ' create the database failed: ' . Mysqli_error ($ Conn)); 
} 
echo " database RUNOOB successfully created \ n " ; 
mysqli_close ($ conn); 
? >

 

Guess you like

Origin www.cnblogs.com/tszr/p/12112937.html