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
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
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.