Mysql Create and delete database commands and related PHP scripts how to operate _mysql

Source: Internet
Author: User
Tags mysql create php script create database

Using Mysqladmin to create a database
with ordinary users, you may need specific permissions to create or delete MySQL databases.
So we're logged in with the root user and the root user has the highest privileges and can use the MySQL mysqladmin command to create the database.
Instance
The following command briefly demonstrates the process of creating a database named Tutorials:

[root@host]# mysqladmin-u root-p Create tutorials
Enter password:******

The MySQL database tutorials is created after the above command has been successfully executed.
Creating a database using PHP scripts
PHP uses the Mysql_query function to create or delete MySQL databases.
The function has two parameters that return TRUE if the execution succeeds, or FALSE.
Grammar

BOOL mysql_query (SQL, connection);

Instance
The following example demonstrates the use of PHP to create a database:

 
 

To delete a database using mysqladmin
to log on to the MySQL server using a regular user, you may need specific permissions to create or delete MySQL databases.
So we're logged in with the root user and the root user has the highest privileges and can use the MySQL mysqladmin command to create the database.
In the process of deleting a database, it is important to be cautious because all data will disappear after the delete command is executed.
The following instance deletes the database tutorials (the database was created above):

[root@host]# mysqladmin-u root-p Drop Tutorials
Enter password:******

After you perform the delete database command above, a prompt box appears to confirm that the database is actually deleted:

Dropping the "database is" potentially a very bad thing todo.
Any data stored in the database would be destroyed.

Do your really want to drop the ' tutorials ' database [y/n] y
database "tutorials" dropped

To delete a database using a PHP script
PHP uses the Mysql_query function to create or delete MySQL databases.
The function has two parameters that return TRUE if the execution succeeds, or FALSE.
Grammar

BOOL mysql_query (SQL, connection);

Instance
The following example demonstrates the use of the PHP mysql_query function to delete a database:

 
 

Note: When you delete a database using a PHP script, you will not be able to confirm the deletion and delete the specified database directly, so you should be careful when you delete the database.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.