MySQL
MIS 21 – Introduction to Applications Development
Databases
Some of the common databases used
Microsoft Access
Microsoft SQL Server
MySQL
Oracle
PostgreSQL
MySQL
Developed by the company MySQL AB
Currently owned by Oracle Corp
Oneof the popular open-source
databases
Advantages of MySQL over Microsoft Access
Inexpensive or free
Optimized for networks
Can handle large quantities of data
Available
over many platforms
(Windows, Mac, Linux)
Logging in to MySQL
Login by using the command:
mysql -u root -p
Type root as password
All
MySQL commands, including queries (e.g.
SELECT) will be done while logged in
Ifthe command is not recognized, go to the bin folder
of MySQL via the command prompt
cd "C:\Program Files\MySQL\MySQL Server
5.0\bin"
Displaying Databases
Use the command below to get a list of
the databases in your computer’s
MySQL
NOTE: Do not forget the semi-colon after
each command
show databases;
Creating and Removing a Database
When making a new database, use:
create database school;
And removing an existing database, use:
drop database school;
NOTE: There is no undo when deleting in
MySQL. It is important to have backup files.
Creating a Backup File
Tocreate backup file, logout of MySQL by
typing quit
Usemysqldump to copy the structure and
contents of a database to a backup file
mysqldump -u root -p school >
"backup2.sql"
Restoring a Backup File
Torestore a backup file, logout of MySQL
by typing quit
Usemysql to copy the structure and
contents of a database from a backup file
mysql -u root -p school <
"backup.sql"
Using a Database and Listing
Tables
Toexecute queries, login MySQL and type
the command:
use school;
This allows MySQL to know which database to
use when querying
To get the tables in a database, use:
show tables;
Displaying the Structure of a Table
Ifyou want to get the fields and
types of each field of a particular
table, use the command:
describe student;