MySQL Database System Installation Overview SQL summary

Slides:



Advertisements
Similar presentations
Session 2Introduction to Database Technology Data Types and Table Creation.
Advertisements

MySQL. To start go to Login details: login: labuser password:macimd15 – There.
MySQL 5.6 Database System Presented by: Abhishek Kothari Computer Science, UGA 02/19/2013.
Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.
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.
Faculty of Sciences and Social Sciences HOPE PHP & MySQL Stewart Blakeway FML 213
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
DT211 Stage 2 Databases Lab 1. Get to know SQL Server SQL server has 2 parts: –A client, running on your machine, in the lab. You access the database.
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.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
SQL Basics+ Brandon Checketts. Why SQL? Structured Query Language Structured Query Language Frees programmers from dealing with specifics of data persistence.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
1 Chapter 8 – Working with Databases spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
INTERNET APPLICATION DEVELOPMENT For More visit:
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
CHAPTER 8 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
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.
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
LIS651 lecture 6 mySQL Thomas Krichel
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
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.
Introduction to Internet Databases MySQL Database System Database Systems.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
CSC 2720 Building Web Applications Database and SQL.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
Database: SQL and MySQL
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
Chapter 10: The Data Tier We discuss back-end data storage for Web applications, relational data, and using the MySQL database server for back-end storage.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Inserting Data.
# 1# 1 Creating Tables, Setting Constraints, and Datatypes What is a constraint and why do we use it? What is a datatype? What does CHAR mean? CS 105.
Sql DDL queries CS 260 Database Systems.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
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.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Intro to MySQL.
Lecture 1.21 SQL Introduction Steven Jones, Genome Sciences Centre.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
3 A Guide to MySQL.
ORDER BY Clause The result of a query can be sorted in ascending or descending order using the optional ORDER BY clause. The simplest form of.
Web Systems & Technologies
Chapter 5 Introduction to SQL.
CS320 Web and Internet Programming SQL and MySQL
Understanding SQL Statements
CIS 136 Building Mobile Apps
 2012 Pearson Education, Inc. All rights reserved.
Open Source Server Side Scripting Permissions & Users
ORACLE SQL Developer & SQLPLUS Statements
Chapter 8 Working with Databases and MySQL
Database systems Lecture 2 – Data Types
CIS 136 Building Mobile Apps
MySQL Database System Installation Overview SQL summary
CS3220 Web and Internet Programming SQL and MySQL
Chapter 4 Introduction to MySQL.
CS3220 Web and Internet Programming SQL and MySQL
MySQL Database System Installation Overview SQL summary
Database Instructor: Bei Kang.
CS4540 Special Topics in Web Development SQL and MS SQL
Presentation transcript:

MySQL Database System Installation Overview SQL summary

2-Tier Architecture Web Server Web Browser (Client) PHP 4/23/2019 BGA

3-Tier Architecture Web Browser (Client) Web Server Database Server PHP 4/23/2019 BGA

SQL links Tutorials MySQL online reference manual http://www.w3schools.com/sql/ http://www.sqlzoo.net http://sqlcourse.com (part 2) http://sqlcourse2/com (part 1) MySQL online reference manual http://dev.mysql.com/doc/mysql/en/Reference.html 4/23/2019 BGA

Command Line Client The standard command line client is c:\mysql\bin\mysql.exe The command line client can be used to send commands and SQL queries to the MySQL server There are also GUI clients such as MyCC 4/23/2019 BGA

Client-Server Interaction Make a request (SQL query) MySQL Server Client Program Get results Client program can be a MySQL command line client, GUI client, or a program written in any language such as C, Perl, PHP, Java that has an interface to the MySQL server. 4/23/2019 BGA

Connecting to the Server Use a command prompt that sets the path to c:\mysql\bin The following command connects to the server: mysql -u root -p you are prompted for the root password. you can now send comands and SQL statements to the server 4/23/2019 BGA

Entering commands (1) Show all the databases SHOW DATABASES; mysql> SHOW DATABASES; +-------------+ | Database | +-------------+ | bookstore | | employee_db | | mysql | | student_db | | test | | web_db | +-------------+ 4/23/2019 BGA

Entering commands (2) Choosing a database and showing its tables USE test; SHOW tables; mysql> USE test; Database changed mysql> SHOW tables; +----------------+ | Tables_in_test | +----------------+ | books | | name2 | | names | | test | +----------------+ 4 rows in set (0.00 sec) mysql> 4/23/2019 BGA

Entering commands (3) Show the structure of a table DESCRIBE names; mysql> DESCRIBE names; +-----------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+----------------+ | id | int(11) | | PRI | NULL | auto_increment | | firstName | varchar(20) | | | | | | lastName | varchar(20) | | | | | +-----------+-------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec) mysql> 4/23/2019 BGA

Entering commands (4) Show the rows of a table (all columns) SELECT * FROM names; mysql> SELECT * FROM names; +----+-----------+------------+ | id | firstName | lastName | +----+-----------+------------+ | 1 | Fred | Flintstone | | 2 | Barney | Rubble | +----+-----------+------------+ 2 rows in set (0.00 sec) mysql> 4/23/2019 BGA

Entering commands (5) Inserting a new record INSERT INTO names (firstName, lastName) VALUES ('Rock','Quarry'); SELECT * FROM names; mysql> INSERT INTO names (firstName, lastName) VALUES ('Ralph', 'Quarry'); Query OK, 1 row affected (0.02 sec) mysql> SELECT * FROM names; +----+-----------+------------+ | id | firstName | lastName | +----+-----------+------------+ | 1 | Fred | Flintstone | | 2 | Barney | Rubble | | 3 | Ralph | Quarry | +----+-----------+------------+ 3 rows in set (0.00 sec) mysql> 4/23/2019 BGA

Entering commands (6) Updating a record UPDATE names SET lastName = 'Stone' WHERE id=3; SELECT * FROM names; mysql> UPDATE names SET lastName = 'Stone' WHERE id=3; Query OK, 1 row affected (0.28 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT * FROM names; +----+-----------+------------+ | id | firstName | lastName | +----+-----------+------------+ | 1 | Fred | Flintstone | | 2 | Barney | Rubble | | 3 | Ralph | Stone | +----+-----------+------------+ 3 rows in set (0.00 sec) mysql> 4/23/2019 BGA

Executing SQL files It is usually better to use an editor to write an SQL script and send it to the server. A file of SQL commands such as books.sql can be executed by the server by using a command such as C:\mysql\bin\mysql -u root -p < books.sql This assumes that books.sql is in your current directory. Otherwise the complete path to books.sql must be supplied 4/23/2019 BGA

Database concepts (1) A relational database management system consists of a number of databases. Each database consists of a number of tables. Example table column headings isbn title author pub year price books table rows (records) 4/23/2019 BGA

Some SQL data types (1) Each entry in a row has a type specified by the column. Numeric data types TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT FLOAT(display_length, decimals) DOUBLE(display_length, decimals) DECIMAL(display_length, decimals) NUMERIC is the same as DECIMAL 4/23/2019 BGA

Some SQL data types (2) Date and time types DATE DATETIME TIMESTAMP format is YYYY-MM-DD DATETIME format YYYY-MM-DD HH:MM:SS TIMESTAMP format YYYYMMDDHHMMSS TIME format HH:MM:SS YEAR default length is 4 4/23/2019 BGA

SQL data types (3) String types CHAR VARCHAR fixed length string, e.g., CHAR(20) VARCHAR variable length string, e.g., VARCHAR(20) BLOB, TINYBLOB, MEDIUMBLOB, LONGBLOB same as TEXT, TINYTEXT ... ENUM list of items from which value is selected 4/23/2019 BGA

SQL commands SHOW, USE SHOW USE Display databases or tables in current database; Example (command line client): show databases; show tables; USE Specify which database to use Example use bookstore; 4/23/2019 BGA

The CREATE Command (1) CREATE creates a database table CREATE TABLE table_name ( column_name1 column_type1, column_name2 column_type2, ... column_nameN column_typeN ); Note: To create a database use the statement CREATE db_name; 4/23/2019 BGA

The CREATE Command (2) Specifying primary keys CREATE TABLE table_name ( column_name1 column_type1 NOT NULL DEFAULT '0', column_name2 column_type2, ... column_nameN column_typeN, PRIMARY KEY (column_name1) ); 4/23/2019 BGA

The CREATE Command (3) autoincrement primary integer keys CREATE TABLE table_name ( column_name1 column_type1 PRIMARY KEY NOT NULL DEFAULT '0' AUTO_INCREMENT, column_name2 column_type2, ... column_nameN column_typeN, ); 4/23/2019 BGA

Conditional Creation Conditional database creation CREATE DATABASE IF NOT EXISTS db_name; Conditional table creation CREATE TABLE IF NOT EXISTS table_name; 4/23/2019 BGA

The DROP Command To delete databases and tables use the DROP command Examples DROP DATABASE db_name; DROP DATABASE IF EXISTS db_name; DROP TABLE table_name; DROP TABLE IF EXISTS table_name; Note: Don't confuse DROP with DELETE which deletes rows of a table. 4/23/2019 BGA

The INSERT Command Inserting rows into a table INSERT INTO table_name ( col_1, col_2, ..., col_N) VALUES ( val_1, val_2, ..., val_N); String values are enclosed in single quotes by default but double quotes are also allowed. Literal quotes need to be escaped using \' and \" 4/23/2019 BGA

The SELECT Command (1) Selecting rows from a table Simplest form: select all columns Select specified columns Conditional selection of rows SELECT * FROM table_name; SELECT column_list FROM table_name; SELECT column_list FROM table_name WHERE condition; 4/23/2019 BGA

The SELECT Command (2) Specifying ascending row ordering Specifying descending row ordering SELECT column_list FROM table_name WHERE condition ORDER by ASC; SELECT column_list FROM table_name WHERE condition ORDER by DESC; 4/23/2019 BGA

The SELECT Command (3) There are many other variations of the select command. Example: finding the number of records in a table assuming a primary key called id: Can also perform searching using the WHERE option SELECT COUNT(id) FROM table_name 4/23/2019 BGA

The UPDATE Command Used to modify an existing record Conditional update version UPDATE table_name SET col_1 = 'new_value1', ..., col_n = 'new_value2'; UPDATE table_name SET col_1 = 'new_value1', ..., col_n = 'new_value2' WHERE condition; 4/23/2019 BGA

marks.sql (1) studentID first_name last_name mark marks table USE test; CREATE TABLE marks ( studentID SMALLINT AUTO_INCREMENT NOT NULL, first_name VARCHAR(20) NOT NULL, last_name VARCHAR(20) NOT NULL, mark SMALLINT DEFAULT 0 NOT NULL, PRIMARY KEY (studentID) ); 4/23/2019 BGA

marks.sql (2) -- Insert some rows into marks table INSERT INTO marks (first_name, last_name, mark) VALUES ('Fred', 'Jones', 78); INSERT INTO marks (first_name, last_name, mark) VALUES ('Bill', 'James', 67); INSERT INTO marks (first_name, last_name, mark) VALUES ('Carol', 'Smith', 82); INSERT INTO marks (first_name, last_name, mark) VALUES ('Bob', 'Duncan', 60); INSERT INTO marks (first_name, last_name, mark) VALUES ('Joan', 'Davis', 86); 4/23/2019 BGA

Executing The Script within MySQL use a command such as source c:/.........../marks.sql This adds the marks table to the test database 4/23/2019 BGA

The Marks Table Selecting the complete table SELECT * FROM marks; +-----------+------------+-----------+------+ | studentID | first_name | last_name | mark | +-----------+------------+-----------+------+ | 1 | Fred | Jones | 78 | | 2 | Bill | James | 67 | | 3 | Carol | Smith | 82 | | 4 | Bob | Duncan | 60 | | 5 | Joan | Davis | 86 | +-----------+------------+-----------+------+ 5 rows in set (0.00 sec) 4/23/2019 BGA