MySQL lecture

2,222 views
2,013 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,222
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
42
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • CRUD stands for Create, Read (Select), Update, and Delete. These are the four main operations performed against a database. SQL (Structured Query Language) is a standard dialect for communicating with a database using terms like “INSERT” for creating data, “SELECT” for querying data, “UPDATE” for updating data, and “DELETE” for deleting data.
  • Examples of an entity include real world object like a Vehicle, Employee, Order, or events like a Service Outage or a System Error. It’s the “thing” or set of things that a database represents, and the real-world objects around which businesses are based. Examples of Vehicle fields include properties of the Vehicle entity, such as the Vehicle year, make, model, and mileage. A record represents all the fields that describe the entity. If our database contains 3000 Vehicles, then it will have 300 rows of vehicles, each with their own distinct values in each field. A table is used to keep records for one entity separate from other entities, so that Vehicle records are stored separately from Employee records. In some ways, you can think of a table as a spreadsheet containing multiple rows and columns all related to the same entity. MySQL server contains multiple databases, which is common for database servers. Each database usually contains tables that are specific to an application or business group.
  • Once you have installed MySQL and have started the command line client using the instructions provided in the Lesson 6 instructions, you will see a mysql> prompt. Enter the above commands at the prompt and begin to explore the databases that come installed with MySQL.
  • MySQL lecture

    1. 1. MySQL Database Overview MySQL Database Overview Instructor: Rick Palmer, SCWCD [email_address]
    2. 2. Topics Covered <ul><li>Database Concepts </li></ul><ul><li>Standard CRUD Operations using MySQL </li></ul>
    3. 3. Database Concepts Refresher <ul><li>Entity: an object, concept, or event. </li></ul><ul><li>Field (column): describes a single characteristic of an entity. </li></ul><ul><li>Record (row): collection of fields (characteristics) describing each entity. </li></ul><ul><li>Table: collection of records for a specific entity. </li></ul><ul><li>Database: collection of tables. </li></ul>
    4. 4. MySQL <ul><li>Open Source relational database management system: www.mysql.com </li></ul><ul><li>Supports Structured Query Language (SQL) – a standardized way to communicate with databases. </li></ul><ul><li>Very popular (NASA, Yahoo, Powell's Books, Novell, U.S. Census Bureau, etc) </li></ul>
    5. 5. Navigating in MySQL <ul><li>Get a list of existing databases: </li></ul><ul><ul><li>mysql> show databases; </li></ul></ul><ul><li>Specify the database to use: </li></ul><ul><ul><li>mysql> use mysql; </li></ul></ul><ul><li>Get a list of tables in the database: </li></ul><ul><ul><li>mysql> show tables; </li></ul></ul><ul><li>Describe a table: </li></ul><ul><ul><li>mysql> describe user; </li></ul></ul>
    6. 6. MySQL C RUD Operations <ul><li>Create a new database: </li></ul><ul><ul><li>mysql> CREATE DATABASE cis; </li></ul></ul><ul><li>Create a new table: </li></ul><ul><ul><li>mysql> use cis; </li></ul></ul><ul><ul><li>-> CREATE TABLE vehicles </li></ul></ul><ul><ul><li>-> (VIN varchar(17), Year int(4), Make varchar(20), </li></ul></ul><ul><ul><li>-> Model varchar(20), Mileage int(10)); </li></ul></ul><ul><li>Insert data into the table: </li></ul><ul><li> mysql> INSERT INTO vehicles (VIN, Year, Make, Model, Mileage) </li></ul><ul><li>-> VALUES ('8YTR754', 2002, 'Ford', 'Mustang', 21000); </li></ul><ul><li>Create a SQL script describing the database : </li></ul><ul><li> C:mysqlin > mysqldump –u root –p cis > cis.sql </li></ul><ul><li>Create a database and data using a SQL script: </li></ul><ul><li> mysql> source C:mysql bincis.sql (NOTE: no semi-colon) </li></ul>
    7. 7. MySQL C R UD Operations <ul><li>Retrieving all data from a table: </li></ul><ul><ul><li>mysql> SELECT * FROM vehicles; </li></ul></ul><ul><ul><li>+----------+-------+-----------+----------+----------+ </li></ul></ul><ul><ul><li>| VIN | Year | Make | Model | Mileage | </li></ul></ul><ul><ul><li>+----------+-------+-----------+----------+----------+ </li></ul></ul><ul><ul><li>| 8YTR754 | 2002 | Ford | Mustang | 21000 | </li></ul></ul><ul><ul><li>| 4GKU390 | 2001 | Chevrolet | Corvette | 35000 | </li></ul></ul><ul><ul><li>| 92A84UJ | 1998 | Dodge | Viper | 89256 | </li></ul></ul><ul><ul><li>+----------+-------+-----------+----------+----------+ </li></ul></ul><ul><li>Selecting a specific row of data: </li></ul><ul><ul><li>mysql> SELECT * FROM vehicles WHERE VIN = '8YTR754'; </li></ul></ul><ul><ul><li>+----------+-------+-----------+----------+----------+ </li></ul></ul><ul><ul><li>| VIN | Year | Make | Model | Mileage | </li></ul></ul><ul><ul><li>+----------+-------+-----------+----------+----------+ </li></ul></ul><ul><ul><li>| 8YTR754 | 2002 | Ford | Mustang | 21000 | </li></ul></ul><ul><ul><li>+----------+-------+-----------+----------+----------+ </li></ul></ul>
    8. 8. MySQL CR U D Operations <ul><li>Update all records in a table </li></ul><ul><li> mysql> UPDATE vehicles SET Mileage = 25000; </li></ul><ul><li>Update specific records </li></ul><ul><li> mysql> UPDATE vehicles SET Mileage = 25000 </li></ul><ul><li> -> WHERE VIN = '8YTR754'; </li></ul><ul><li>Update multiple columns of a specific record </li></ul><ul><li> mysql> UPDATE vehicles </li></ul><ul><li>-> SET Mileage = 25000, LastServiceDate = '08/30/2003' </li></ul><ul><li>-> WHERE VIN = '8YTR754'; </li></ul>
    9. 9. MySQL CRU D Operations <ul><li>Delete all rows in a table (does not delete table) </li></ul><ul><li> mysql> DELETE FROM vehicles; </li></ul><ul><li>Delete specific rows in a table </li></ul><ul><li> mysql> DELETE FROM vehicles </li></ul><ul><li> -> WHERE VIN = '8YTR754'; </li></ul><ul><li>Delete the entire table (remove from database) </li></ul><ul><li> mysql> DROP TABLE vehicles; </li></ul>

    ×