Professional Documents
Culture Documents
MODULE7
MODULE7
Module #7
Name: _______________________________________________________________
Section: ____________ Date: ________________
MAIN LESSON
MySQL is one of the most popular relational database management systems. It is developed and maintained by the
Oracle Corporation. Other than Drupal, Joomla, and WordPress, MySQL is used by global brands like Facebook,
Flickr, Twitter, and YouTube.
What is SQL?
In the above section, we learned what we do with the database using SQL. SQL is basically combination of four
different languages, they are:
ü DQL (Data Query Language)
DQL is used to fetch the information from the database which is already stored there.
ü DDL (Data Definition Language)
DDL is used to define table schemas.
ü DCL (Data Control Language)
DCL is used for user & permission management. It controls the access to the database.
ü DML (Data Manipulation Language)
DML is used for inserting, updating and deleting data from the database.
What is a Query?
A Query is a set of instruction given to the database management system, which tells RDBMS what
information you would like to get from the database.
For e.g. to fetch the employee name from the database table EMPLOYEE, we write the SQL Query like this:
Name: _______________________________________________________________
Section: ____________ Date: ________________
1. Numeric - Numeric data types are used to store numeric values. It is very important to make sure range of
your data is between lower and upper boundaries of numeric data types
2. Text - As data type category name implies these are used to store text values. Always make sure you
length of your textual data do not exceed maximum lengths.
3. Date/time.
.
IM211:FUNDAMENTALS OF DATABASE SYSTEMS
Module #7
Name: _______________________________________________________________
Section: ____________ Date: ________________
List of Commands
There you go! I’m expecting that you learn something today, I am excited to
hear your understanding with our lesson for today, Answer the following
question:
On this activity, you are going to follow the given instruction on how to access and create a database in MySQL and
MySQL Workbench.
You start a create database statement by specifying the database name. It must be unique within the MySQL server
instance. If you give a name to the database being created that has already been assigned to some other existing
database, then MySQL will generate an error.
It is possible to specify the character set as well as the collation for the new database at the creation time. However,
if you choose not to, then MySQL will use the default character and collation for the newly-created database.
Name: _______________________________________________________________
Section: ____________ Date: ________________
Step 1 - Log in to the MySQL as the root user. For this, use the following command:
>mysql -u root -p
Now, you will be prompted to enter the root user password, like this:
Enter password: _
Step 3 - Now, use the CREATE DATABASE command for creating a new database in the MySQL server instance
as demonstrated below:
mysql> CREATE DATABASE database_name;
For reviewing the newly created database, you can use the SHOW CREATE DATABASE command:
mysql> SHOW CREATE DATABASE database_name;
It will return the database details along with the character set and collation for the same.
Step 4 - To access the newly created database, use the USE command, demonstrated as follows:
mysql> USE database_name;
Database changed
You can start creating tables, storing values, etc. in the newly created database from here on.
Obviously, you can also create a database in MySQL using the MySQL Workbench. However, in doing so, you don’t
need to use the CREATE DATABASE command. Instead, you will create a database graphically i.e. by entering
some details and doing a lot of clicking.
Here is the step-by-step procedure for creating a new database with the MySQL Workbench:
Step 1 - Launch the MySQL Workbench and click on the Setup New Connection button (It is the one with
the ‘+ contained in a circle’ symbol)
Step 2 - Enter name for the connection followed by clicking the Test Connection button
Step 3 - You will now be prompted with a dialogue box, requesting the root password. Enter it, check the
Save password in vault checkbox (if not done already) and hit the Ok button
Step 4 - Next, double-click the Local connection name in order to connect to the MySQL server instance.
Now you will be taken to the main MySQL Workbench window consisting 4 sections, namely Information,
Navigator, Output, and Query
Step 5 - Click on the create a new schema in the connected server button present in the toolbar (In MySQL,
the schema is just another name for referring a database)
Step 6 - A window will now pop up. Supply it with the schema name and change the character set and
collation settings, if needs be. Finally, click on the Apply button
IM211:FUNDAMENTALS OF DATABASE SYSTEMS
Module #7
Name: _______________________________________________________________
Section: ____________ Date: ________________
Step 7 - Next, MySQL Workbench will open a window displaying the SQL script that will be executed. You
will notice a CREATE SCHEMA command here, which is equivalent to the CREATE DATABASE command.
As such, it is followed by the database name. To continue, click on the Apply button
Step 8 - The newly created database will be reflected in the SCHEMAS tab present in the Navigator section
of the MySQL Workbench window
Step 9 - To select the newly created database, right-click on it and select the Set as Default Schema option
Now, you are able to work with the newly created database via the MySQL Workbench. You can now add new
tables and data to the database from here or from the MySQL program as you find suitable.
Name: _______________________________________________________________
Section: ____________ Date: ________________
What is a Query