Preliminary Definitions MySQL: An Open Source, Enterprise-level, multi-threaded, relational database management system that stores and retrieves data using.

Slides:



Advertisements
Similar presentations
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.
Advertisements

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.
Introduction to Structured Query Language (SQL)
Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Concepts of Database Management Sixth Edition
Introduction to Structured Query Language (SQL)
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.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
CSC 2720 Building Web Applications Database and SQL.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
MySQL/PHP Workshop 2 MySQL lectures 2 PHP lectures Each lecture builds on concepts taught and learned in the previous lectures. The first two lectures.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Chapter 9 Database Management
Phil Brewster  One of the first steps – identify the proper data types  Decide how data (in columns) should be stored and used.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
CSCI 6962: Server-side Design and Programming
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Preliminary Definitions MySQL: An Open Source, Enterprise-level, multi-threaded, relational database management system that stores and retrieves data using.
Database Lecture # 1 By Ubaid Ullah.
Copyright © 2003 by Prentice Hall Module 4 Database Management Systems 1.What is a database? Data hierarchy and data organization Field, record, file,
ASP.NET Programming with C# and SQL Server First Edition
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Class #2: Introduction to MySQL (Continued) Where clause (continued) Aggregate Functions Creating users Backing up your database Indexes (if time) Importing.
Chapter 4 The Relational Model 3: Advanced Topics Concepts of Database Management Seventh Edition.
Information Systems Today (©2006 Prentice Hall) MySQL 1CS3754 Class Note #8, Is an open-source relational database management system 2.Is fast and.
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.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Introduction to MySQL Lab no. 10 Advance Database Management System.
Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
CSC 2720 Building Web Applications Database and SQL.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Database Fred Durao What is a database? A database is any organized collection of data. Some examples of databases you may encounter in.
Discovering Computers Fundamentals Fifth Edition Chapter 9 Database Management.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
Most information comes from Chapter 3, MySQL Tutorial: 1 MySQL: Part.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Advanced Web 2012 Lecture 3 Sean Costain What is a Database? Sean Costain 2012 A database is a structured way of dealing with structured information.
Visual Programing SQL Overview Section 1.
Database Management Supplement 1. 2 I. The Hierarchy of Data Database File (Entity, Table) Record (info for a specific entity, Row) Field (Attribute,
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Lesson 2: Designing a Database and Creating Tables.
Information Systems Today: Managing in the Digital World TB3-1 3 Technology Briefing Database Management “Modern organizations are said to be drowning.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
What is MySQL? MySQL is a relational database management system (RDBMS) based on SQL (Structured Query Language). First released in January, Many.
Relational Databases and MySQL. Relational Databases Relational databases model data by storing rows and columns in tables. The power of the relational.
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.
11-1 © Prentice Hall, 2004 Chapter 11: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
Lab 3.21 MySQL Database Lab Developing the Tools May 5 th, 2004 Montréal, Québec Dominik Gehl Hôpital Ste-Justine, Montréal.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
Software-Projekt 2008 Seminarvortrag“Short tutorial of MySql“ Wei Chen Verena Honsel.
CS320 Web and Internet Programming SQL and MySQL
Databases and Information Management
Chapter 7 Working with Databases and MySQL
Chapter 8 Working with Databases and MySQL
Computer Science Projects Database Theory / Prototypes
CS3220 Web and Internet Programming SQL and MySQL
CS3220 Web and Internet Programming SQL and MySQL
Introduction to MySQL NELINET October 28th, 2005.
Presentation transcript:

Preliminary Definitions MySQL: An Open Source, Enterprise-level, multi-threaded, relational database management system that stores and retrieves data using the Structured Query Language o licensed with the GNU General public license Structured Query Language (SQL): A standardized query language for getting information from a relational database. Relational Database: A database that stores data in the form of relational tables as 0pposed to flat files. Database Management System (DBMS): A system that manages relational databases; A collection of programs that enabling the storage, modification, and extraction of information from a database.

Main Features Fully multi-threaded using kernel threads. Works on many different platforms. Many column types Very fast joins using an optimized one-sweep multi-join Full operator and function support in the SELECT and WHERE parts of queries. You can mix tables from different databases in the same query. A privilege and password system that is very flexible and secure. Handles large databases. Tested with a broad range of different compilers. (C/C++) No memory leaks. Full support for several different character sets.

Cells, Rows, Tables and Databases Cell -- a single (scalar) value.

Cells, Rows, Tables and Databases Row -- a group of scalar values representing a single instance of an object or event.

Cells, Rows, Tables and Databases Table -- a series of rows describing separate objects or events.

Cells, Rows, Tables and Databases Database -- a collection of related tables describing various facets of a group of objects or events.

Relations -- One to One

Relations -- One to Many

Relations -- Many to Many

Relational Databases A database is a collection of tables Columns define attributes of the data o All data in a column must have the same data type A record is stored in a row table name column row

Use a Relational Database When… You have a very large dataset There is redundant data o Wastes disk space o Increases errors Information must be updated in multiple locations Security is important o Different users can be granted different permissions Strict enforcement of data types is important

Spreadsheet Example

Data is inconsistent! Now imagine you are designing the New York Public Library database which has tens of million books and well over a million cardholders.

Database Design Entity Relationship Design Entity (“thing”, “object”)Table Attributes (describe entity)Columns Entity InstanceRow Relationships between entities preserved in relationships between tables. If you are interested in learning more formal design methods look up “normalization” and/or “third normal form”.

Our data Ensembl Gene IDSymbol / Name Chromo some Start Position (bp) End Position (bp) LocusLink ID Taxonomy ID Common Name Species ENSG TNFRSF humanHomo sapiens ENSG CAB humanHomo sapiens ENSG B3GALT humanHomo sapiens ENSG UBE2J humanHomo sapiens ENSG SCNN1D humanHomo sapiens ENSG MGC humanHomo sapiens ENSG AKIP humanHomo sapiens ENSG MRPL humanHomo sapiens ENSG WARP humanHomo sapiens ENSG ATAD3B humanHomo sapiens ENSG CDC2L humanHomo sapiens ENSG SLC35E humanHomo sapiens ENSG FLJ humanHomo sapiens ENSG GNB humanHomo sapiens ENSMUSG TNFRSF mouseMus musculus ENSMUSG UBE2J mouseMus musculus What entities or “objects” are defined here? Is there any redundant data? What happens if we want to add another species attribute (e.g. genus)?

Our tables How do we know which organism a gene belongs to? Do we have unique identifiers? Can the organism have more than one gene? Can the gene have more than one organism?

Our tables Means each gene has “one and only one” organism, but that each organism can have more than one gene. This is an example of an entity relationship diagram.

Our tables A primary key is a unique identifier for a record in a table. A foreign key in one table refers to the primary key of another. The gene table has a foreign key, Organism_ID. Each record in the gene table will have an organism id to link it to the correct species record in the organism table.

Database Design Caveat Sometimes design is “sacrificed” for speed.

Data Types float integer tinyint varchar(size) o stores strings o size can be between , inclusive datetime + more What data types should our attributes (columns) be?

Complete Design Gene ColumnData Type gene_idinteger ensembl_gene_idvarchar(50) organism_idinteger namevarchar(35) locuslinkvarchar(10) chromosometinyint chromo_startinteger chromo_endinteger descriptionvarchar(255 ) Organism ColumnData Type organism_idinteger taxonomy_idinteger common_namevarchar(35) speciesvarchar(35) Database name: ensmartdb

Connecting to MySQL from the Command Line mysql -uusername -p Example: >mysql -uroot To EXIT MySQL: EXIT;

Basic SQL Commands SQL statements end with a semicolon View databases SHOW DATABASES;

START A MYSQL CLIENT Without using passwords (when the password for the specified user is empty) mysql -u -h Using passwords mysql -u -h -p Example: mysql -u root -h localhost Exitting with the command quit or exit.

DATA MANAGEMENT SHOW DATABASES; USE databaseName; SHOW TABLES; DESCRIBE table; SELECT * FROM table; SELECT * FROM table \G CREATE DATABASE databaseName; DROP DATABASE databaseName; CREATE TABLE tableName(name1 type1, name2 type2,...); DROP TABLE tableName; INSERT INTO TABLE VALUES( value1, value2,...); SELECT field1, field2,... FROM tableName; SELECT * INTO OUTFILE 'C:/tmp/skr.txt' FROM skr; LOAD DATA INFILE /path/file.txt INTO TABLE skr;

Importing a Database Creating a database CREATE DATABASE trii; From the command line: mysql -uusername -ppassword databasename < filename.sql Example: o mysql -uroot trii < trii.sql

Use database databasename USE databasename; Display all tables in a database SHOW TABLES; Basic SQL Commands

Create Table CREATE TABLE organism ( organism_id INTEGER NOT NULL AUTO_INCREMENT, taxonomy_id INTEGER NOT NULL, common_name VARCHAR(35) NOT NULL, species VARCHAR(35) NOT NULL, PRIMARY KEY (organism_id), UNIQUE (taxonomy_id) ); database name column names

View column details for a table DESC tablename;

Selecting all data SELECT * FROM tablename;

Select only the columns you need (it will be faster) SELECT common_name, species FROM organism;

Limiting your data Get the species name for a specific organism (you have the id) SELECT species FROM organism WHERE organism_id=1; How do we select all the gene names for chromosome 1?

Insert Inserting a gene INSERT INTO gene (ensembl_gene_id, organism_id, name, chromosome, chromo_start, chromo_end) VALUES (‘MY_NEW_GENE’, 1, ‘MY GENE’, 1, 12345, 67890); Get the id of the gene: SELECT gene_id FROM gene WHERE name='MY GENE';

Delete/Update Deleting a gene DELETE FROM gene WHERE gene_id=19; Updating a gene UPDATE gene SET name=‘NEW NAME’ WHERE name=‘AKIP’;

Documentation p As text manual.txt As HTML manual_toc.html As GNU Infomysql.info As PostScript manual.ps

PHPMyAdmin Web application Makes it easier to use MySQL To launch: Download it here: downloads.php

Create Database Enter name of database here and click “Create” You are logged in as “root” To get back to this page at any time select “Databases”

Create Table SQL query used to create “ensmartdb” Enter table name and number of fields then click “Go” We are currently using this database

Define Columns Select “auto_increment” here Select “Primary” here since this is the primary key Don’t forget to click “Save”! We are defining the columns for table “gene”

View Database Select “ensmartdb” to view tables in database Click “gene” to view “gene” table Add another table here

Insert Data Don’t forget to save by clicking “Go”! Click on “insert” to add data to table

View/Delete/Edit Data Check rows to edit or delete Click here to edit checked rows Click here to delete checked rows Click on “Browse” to view/edit/delete data

Database Users To use MySQL you must have a username and password A user in MySQL has permissions set regarding o MySQL itself (ex. whether or not the user can create a database) o Specific databases within MySQL For example, user “guest” may have permission to view database “x” but not database “y” Multiple users can access a MySQL database simultaneously

Granting a User Privileges PHPMyAdmin is logged in as user “root”, and has permission to do anything You should NOT make a habit of connecting to your database as root Create a user with restricted permissions to your database instead Click “Add new User”

Granting a User Privileges (Continued) Enter “User name”, “Host”, and “Password” This are privileges the user will have on ALL databases

Granting a User Privileges (Continued) Select “ensmartdb” to edit user permissions for database “ensmartdb” On the next screen select ONLY the permissions the user must have After you save the “global” permissions, you may add database specific permissions