Manage Database in MySQL

download Manage Database in MySQL

of 3

Transcript of Manage Database in MySQL

  • 8/12/2019 Manage Database in MySQL

    1/3

    Manage Database in MySQL

    Summary: in this tutorial, you will learn how to manage databases in MySQL. You will learnhow to create a new databases, remove databases from database catalog and display alldatabases in the MySQL database server.

    Lets start creating a new database in MySQL.

    Creating Database

    Before doing anything else with the data, you need to create a database. A database is acontainer of data. It stores contacts, vendors, customers or any kind of data you can thinkof. In MySQL, a database is a collection of objects that are used to store and manipulatedata such as tables,database views,triggers,stored proceduresetc.

    To create a database in MySQL, you use CREATE DATABASE statement as follows:

    ?

    1 CREATEDATABASE[IF NOTEXISTS] database_name;

    Lets examine the CREATE DATABASE statement in greater detail:

    Followed by CREATE DATABASE statement is database name that you wantto create. It is recommended that database name should be meaningful anddescriptive.

    The IF NOT EXISTS is an optional element of the statement. The IF NOTEXISTS statement prevents you from error of creating a new database thatalready exists in the database catalog. You cannot have 2 databases with thesame name in a same database catalog.

    For example, to create classicmodelsdatabase, you need to execute the CREATEDATABASE statement as follows:

    ?

    1 CREATEDATABASEclassicmodels;

    After executing the statement, MySQL will returns a message to notify if the new databasehas been created successfully.

    http://www.mysqltutorial.org/mysql-views-tutorial.aspxhttp://www.mysqltutorial.org/mysql-views-tutorial.aspxhttp://www.mysqltutorial.org/mysql-views-tutorial.aspxhttp://www.mysqltutorial.org/mysql-triggers.aspxhttp://www.mysqltutorial.org/mysql-triggers.aspxhttp://www.mysqltutorial.org/mysql-triggers.aspxhttp://www.mysqltutorial.org/mysql-stored-procedure-tutorial.aspxhttp://www.mysqltutorial.org/mysql-stored-procedure-tutorial.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-stored-procedure-tutorial.aspxhttp://www.mysqltutorial.org/mysql-triggers.aspxhttp://www.mysqltutorial.org/mysql-views-tutorial.aspx
  • 8/12/2019 Manage Database in MySQL

    2/3

    Displaying Databases

    SHOW DATABASE statement displays all databases in your database server. You can useSHOW DATABASE statement to check the database youve created or to see all thedatabases on the database server before you create a new database, for example:

    ?

    1 SHOW DATABASES;

    Selecting a database to work with

    Before working with database you must tell MySQL which database you want to work withby using the USE statement.

    ?

    1 USE database_name;

    You can select thesample databaseclassicmodelsusing the USE statement as follows:

    ?

    1 USE classicmodels;

    From now on all operations such asquerying data,create new tablesorstored procedureswhich you perform, will take effects on the current database.

    Removing Databases

    Removing database means you delete the database physically. All the data and relatedobjects inside the database are permanently deleted and cannot be undone. So it is veryimportant to execute this query with extra cautions. To delete a database, you use theDROP DATABASE statement as follows:

    ?

    http://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-sample-database.aspxhttp://www.mysqltutorial.org/mysql-sample-database.aspxhttp://www.mysqltutorial.org/mysql-sample-database.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-select-statement-query-data.aspxhttp://www.mysqltutorial.org/mysql-select-statement-query-data.aspxhttp://www.mysqltutorial.org/mysql-select-statement-query-data.aspxhttp://www.mysqltutorial.org/mysql-create-table/http://www.mysqltutorial.org/mysql-create-table/http://www.mysqltutorial.org/mysql-create-table/http://www.mysqltutorial.org/mysql-stored-procedure-tutorial.aspxhttp://www.mysqltutorial.org/mysql-stored-procedure-tutorial.aspxhttp://www.mysqltutorial.org/mysql-stored-procedure-tutorial.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-stored-procedure-tutorial.aspxhttp://www.mysqltutorial.org/mysql-create-table/http://www.mysqltutorial.org/mysql-select-statement-query-data.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-sample-database.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspxhttp://www.mysqltutorial.org/mysql-create-drop-database.aspx
  • 8/12/2019 Manage Database in MySQL

    3/3