Introduction to MySQL.

Slides:



Advertisements
Similar presentations
Introduction to MySQL. 2 Road Map Introduction to MySQL Connecting and Disconnecting Entering Basic Queries Creating and Using a Database.
Advertisements

Introduction to MySQL. 2 Road Map  Introduction to MySQL  Connecting and Disconnecting  Entering Basic Queries  Creating and Using a Database.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
What is MySQL? MySQL is a relational database management system (A relational database stores data in separate tables rather than putting all the data.
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
Quick-and-dirty.  Commands end in a semi-colon ◦ If you forget, another prompt line shows up  Either continue the command or…  End it with a semi-colon.
How to Use MySQL CS430 March 18, SQL: “Structured Query Language”—the most common standardized language used to access databases. SQL has several.
1 Table Alteration. 2 Altering Tables Table definition can be altered after its creation Adding columns Changing columns’ definition Dropping columns.
CS34311 CS3431 – Database Systems I Project Overview Murali Mani.
7/2/2015Murali Mani -- CS5421 Database Management Systems DB Application Development Project Statement + Introduction to Oracle.
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
1 Working with MS SQL Server II. 2 The sqlcmd Utility Command line utility for MS SQL Server databases. Previous version called osql Available on classroom.
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
Databases with PHP A quick introduction. Y’all know SQL and Databases  You put data in  You get data out  You can do processing on it very easily 
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
JDBC Java Database Connectivity. What is an RDBMS? Relational database management system. There are other kinds of DBMS. Access is a GUI on a JET RBDMS.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
Information Systems Today (©2006 Prentice Hall) MySQL 1CS3754 Class Note #8, Is an open-source relational database management system 2.Is fast and.
CpSc 462/662: Database Management Systems (DBMS) (TEXNH Approach) SQL and MySQL James Wang.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Ways to manage DB in MySQL cs346. Six ways to CREATE and INSERT INTO tables Modelocalremotelocalremotewindow WhereMysql console Putty; Mysql console Mysql.
1 Working with MS SQL Server Textbook Chapter 14.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD.
Introduction to Internet Databases MySQL Database System Database Systems.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
Chapter 5 MYSQL Database. Introduction to MYSQL MySQL is the world's most popular open-source database. Open source means that the source code, the programming.
Most information comes from Chapter 3, MySQL Tutorial: 1 MySQL: Part.
Personal Oracle8i Create a new user Create a new table Enter data into a new table Export & import data Start and exit SQL Plus SQL Plus Syntax.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
CpSc 462/662: Database Management Systems (DBMS) MySQL.
SQL has several parts: Major ones: DDL – Data Definition Language {Defining, Deleting, Modifying relation schemas} DML – Data Manipulation Language {Inserting,
Personal Oracle8i Create a new user Create a new table Enter data into a new table Export & import data Start and exit SQL Plus SQL Plus Syntax.
Chungbuk HRDI of KCCI PhD Kang,Won-Chan PHP Programming (MySQL)
Mysql YUN YEO JOONG. 1 Connecting to and Disconnecting from the Server 1 Connecting to and Disconnecting from the Server shell> mysql – h host -u user.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: Week 3 – MySQL – Statements.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
CCT1343, Week 3 SQL Queries Using Multiple Tables This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
Database Design and Implementation
CCT395, Week 2 Introduction to SQL Yuri Takhteyev September 15, 2010
Dept. of Computer & Information Sciences
3 A Guide to MySQL.
Fundamental of Databases
CS320 Web and Internet Programming SQL and MySQL
MySQL: Part II.
Data Modeling and Database Design INF1343, Winter 2012 Yuri Takhteyev
SQL and SQL*Plus Interaction
CCT1343, Week 2 Single-Table SQL Yuri Takhteyev University of Toronto
Introduction to MySQL.
Basics on DB access Elke A. Rundensteiner.
Introduction to Web programming
Database application MySQL Database and PhpMyAdmin
Chapter 7 Working with Databases and MySQL
Chapter 8 Working with Databases and MySQL
CS1222 Using Relational Databases and SQL
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
Using SQL*Plus.
CS3220 Web and Internet Programming SQL and MySQL
MySQL Database System Installation Overview SQL summary
CS3220 Web and Internet Programming SQL and MySQL
MySQL Database System Installation Overview SQL summary
Introduction to MySQL.
Presentation transcript:

Introduction to MySQL

Road Map Introduction to MySQL Connecting and Disconnecting Entering Basic Queries Creating and Using a Database

MySQL MySQL is a very popular, open source database. Officially pronounced “my Ess Que Ell” (not my sequel). Handles very large databases; very fast performance. Why are we using MySQL? Free (much cheaper than Oracle!) Can be installed MySQL. Easy to use Shell for creating tables, querying tables, etc. Easy to use with Java JDBC

Connecting to MySQL MySQL provides an interactive shell for creating tables, inserting data, etc. On Windows, just go to c:\mysql\bin, and type: mysql Or, click on the Windows icon

Sample Session For example: Enter password: ***** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 241 to server version: 3.23.49 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> To exit the MySQL Shell, just type QUIT or EXIT: mysql> QUIT mysql> exit

Basic Queries Once logged in, you can try some simple queries. For example: mysql> SELECT VERSION(), CURRENT_DATE; +-----------+--------------+ | VERSION() | CURRENT_DATE | | 3.23.49 | 2002-05-26 | 1 row in set (0.00 sec) Note that most MySQL commands end with a semicolon (;) MySQL returns the total number of rows found, and the total time to execute the query.

Basic Queries Keywords may be entered in any lettercase. The following queries are equivalent: mysql> SELECT VERSION(), CURRENT_DATE; mysql> select version(), current_date; mysql> SeLeCt vErSiOn(), current_DATE;

Basic Queries Here's another query. It demonstrates that you can use mysql as a simple calculator: mysql> SELECT SIN(PI()/4), (4+1)*5; +-------------+---------+ | SIN(PI()/4) | (4+1)*5 | | 0.707107 | 25 |

Basic Queries You can also enter multiple statements on a single line. Just end each one with a semicolon: mysql> SELECT VERSION(); SELECT NOW(); +--------------+ | VERSION() | | 3.22.20a-log | +---------------------+ | NOW() | | 2004 00:15:33 |

Multi-Line Commands mysql determines where your statement ends by looking for the terminating semicolon, not by looking for the end of the input line. Here's a simple multiple-line statement: mysql> SELECT -> USER() -> , -> CURRENT_DATE; +--------------------+--------------+ | USER() | CURRENT_DATE | | joesmith@localhost | 1999-03-18 |

Canceling a Command If you decide you don't want to execute a command that you are in the process of entering, cancel it by typing \c mysql> SELECT -> USER() -> \c mysql>

Using a Database To get started on your own database, first check which databases currently exist. Use the SHOW statement to find out which databases currently exist on the server: mysql> show databases; +----------+ | Database | | mysql | | test | 2 rows in set (0.01 sec)

Using a Database To create a new database, issue the “create database” command: mysql> create database webdb; To the select a database, issue the “use” command: mysql> use webdb;

Creating a Table Once you have selected a database, you can view all database tables: mysql> show tables; Empty set (0.02 sec) An empty set indicates that I have not created any tables yet.

Creating a Table Let’s create a table for storing pets. Table: pets name: VARCHAR(20) owner: VARCHAR(20) species: VARCHAR(20) sex: CHAR(1) birth: DATE date: DATE VARCHAR is usually used to store string data.

Creating a Table To create a table, use the CREATE TABLE command: mysql> CREATE TABLE pet ( -> name VARCHAR(20), -> owner VARCHAR(20), -> species VARCHAR(20), -> sex CHAR(1), -> birth DATE, death DATE); Query OK, 0 rows affected (0.04 sec)

Showing Tables To verify that the table has been created: mysql> show tables; +------------------+ | Tables_in_test | | pet | 1 row in set (0.01 sec)

Describing Tables To view a table structure, use the DESCRIBE command: mysql> describe pet; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | | name | varchar(20) | YES | | NULL | | | owner | varchar(20) | YES | | NULL | | | species | varchar(20) | YES | | NULL | | | sex | char(1) | YES | | NULL | | | birth | date | YES | | NULL | | | death | date | YES | | NULL | | 6 rows in set (0.02 sec)

Deleting a Table To delete an entire table, use the DROP TABLE command: mysql> drop table pet; Query OK, 0 rows affected (0.02 sec)

Loading Data Use the INSERT statement to enter data into a table. For example: INSERT INTO pet VALUES ('Fluffy','Harold','cat','f', '1999-02-04',NULL); The next slide shows a full set of sample data.

More data… name owner species sex birth death Fluffy Harold cat f 1993-02-04 Claws Gwen m 1994-03-17 Buffy dog 1989-05-13 Fang Benny 1990-08-27 Bowser Diane 1998-08-31 1995-07-29 Chirpy bird 1998-09-11 Whistler 1997-12-09 Slim snake 1996-04-29

Loading Sample Data You could create a text file `pet.txt' containing one record per line. Values must be separated by tabs, and given in the order in which the columns were listed in the CREATE TABLE statement. Then load the data via the LOAD DATA Command.

Sample Data File Fluffy Harold cat f 1993-02-04 \N Claws Gwen cat m 1994-03-17 \N Buffy Harold dog f 1989-05-13 \N Fang Benny dog m 1990-08-27 \N Bowser Diane dog m 1979-08-31 1995-07-29 Chirpy Gwen bird f 1998-09-11 \N Whistler Gwen bird \N 1997-12-09 \N Slim Benny snake m 1996-04-29 \N To Load pet.txt: mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet;

Thanks…