Now you will learn how to manage databases in MySQL. You will learn
1) How to create a new databases,
2) Display all databases from database server
3) Use database
4) Remove databases from database server
1. Creating Database
Before doing anything else with the data, you need to create a database. A database is a container of data. A database is a collection of objects that are used to store and manipulate data such as tables, database views,triggers, stored procedures…etc.
CREATE DATABASE [IF NOT EXISTS] database_name;
Here database_name is user defined database name.
CREATE DATABASE sales;
After executing the statement, MySQL will returns a message to notify if the new database has been created successfully.
2. Displaying Databases from Database Server
You can use SHOW DATABASE statement to check the database you’ve created or to see all the databases on the database server before you create a new database, for example:
3. Selecting a database to work with
Before working with database you must tell MySQL which database you want to work with by using the USE statement.
From now on all operations such as querying data, create new tables or stored procedures which you perform, will take effects on the current database.
4. Removing Database
Removing database means you delete the database physically. All the data and related objects inside the database are permanently deleted and cannot be undone. So it is very important to execute this query with extra cautions. To delete a database, you use the DROP DATABASE statement as follows:
DROP DATABASE [IF EXISTS] database_name;
DROP DATABASE sales;