Class #2: Introduction to MySQL (Continued) Where clause (continued) Aggregate Functions Creating users Backing up your database Indexes (if time) Importing.

Slides:



Advertisements
Similar presentations
CC SQL Utilities.
Advertisements

Introduction to Structured Query Language (SQL)
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.
Introduction to Structured Query Language (SQL)
ISP 121 Week 1 Introduction to Databases. ISP 121, Winter Why a database and not a spreadsheet? You have too many separate files or too much data.
Concepts of Database Management Sixth Edition
Introduction to Structured Query Language (SQL)
Mary K. Olson PS Reporting Instance – Query Tool 101.
Concepts of Database Management Sixth Edition
Preliminary Definitions MySQL: An Open Source, Enterprise-level, multi-threaded, relational database management system that stores and retrieves data using.
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.
Integrating Databases into the Web with PHP/MySQL CS 4000.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
CSCI 6962: Server-side Design and Programming
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.
INTERNET APPLICATION DEVELOPMENT For More visit:
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Chapter 10 Queries and Updating Part C. SQL Copyright 2005 Radian Publishing Co.
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.
Self Guided Tour for Query V8.4 Basic Features. 2 This Self Guided Tour is meant as a review only for Query V8.4 Basic Features and not as a substitute.
1 MySQL and phpMyAdmin. 2 Navigate to and log on (username: pmadmin)
1 Lesson 22 Getting Started with Access Essentials Computer Literacy BASICS: A Comprehensive Guide to IC 3, 3 rd Edition Morrison / Wells.
MS Access Database Connection. Database? A database is a program that stores data and records in a structured and queryable format. The tools that are.
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.
Introduction to databases and SQL. What is a database?  A database is an organized way of holding together pieces of information  A database refers.
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.
1 Working with MS SQL Server Textbook Chapter 14.
Lesson 17 Getting Started with Access Essentials
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.
CSC 405: Web Application And Engineering II7.1 Database Programming with SQL Aggregation and grouping with GROUP BY Aggregation and grouping with GROUP.
Introduction to MySQL Lab no. 10 Advance Database Management System.
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.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
CSC 240 (Blum)1 Forms and Importing Data in Access.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Inserting Data.
Intro to SQL Management Studio. Please Be Sure!! Make sure that your access is read only. If it isn’t, you have the potential to change data within your.
WIBR Bioinformatics, © Whitehead Institute, 2004 Relational Databases for Biologists Robert Latek, Ph.D. Sr. Bioinformatics Scientist Whitehead Institute.
MySQL Importing and creating a database. CSV (Comma Separated Values) file CSV = Comma Separated Values – they are simple text files containing data which.
Planning & Creating a Database By Ms. Naira Microsoft Access.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
Managing Database With Oracle Replacement for Ch10 COP 4708.
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.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
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.
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.
MySQL and PHPMyAdmin 1. Make sure your MySQL service is running. If using XAMPP, open the control panel. If the button for MySQL says Start, click it.
Open Source Server Side Scripting Permissions & Users
PHP + MySQL Commands Refresher.
Using SQL Server through Command Prompt
MS Access Database Connection
Chapter 7 Working with Databases and MySQL
Chapter 8 Working with Databases and MySQL
Working with Big Data in SQL
HAVING,INDEX,COMMIT & ROLLBACK
8 6 MySQL Special Topics A Guide to MySQL.
Introduction to Web programming
Presentation transcript:

Class #2: Introduction to MySQL (Continued) Where clause (continued) Aggregate Functions Creating users Backing up your database Indexes (if time) Importing large datasets (if time) Make sure you receive Class notes Exercise handout

Where Clause How do you think we can limit the results from the last query to just gene “TNFRSF18”? Remember the query is: SELECT gene.name, organism.species FROM gene, organism WHERE gene.organism_id=organism.organism_id;

Where Clause (Continued) SELECT gene.name, organism.species FROM gene, organism WHERE gene.organism_id=organism.organism_id AND gene.name=‘TNFRSF18’;

Aggregate Functions What if we want to know how many genes we have? SELECT count(gene_id) FROM gene; What if we want to count the number of records for each gene name? SELECT name, COUNT(gene_id) FROM gene GROUP BY name;

What if we want to know how many genes (by name) have more than one record in our gene table? SELECT name, COUNT(gene_id) AS copies FROM gene GROUP BY name HAVING copies>1; Here we restricted the results based on properties of the group. Having Clause

Backing Up your Database From the command line (not in MySQL): mysqldump -uusername -p databasename > filename.sql Example: mysqldump -uroot trii > triibackup.sql (our database has no password) filename.sql will contain all of the SQL statements necessary to first create all the tables in your database and then repopulate them.

Restoring your Database From the command line: mysql -uusername -ppassword databasename < filename.sql Example: mysql -uroot trii < triibackup.sql Notice you must have already recreated the database in MySQL CREATE DATABASE trii;

Inserting Very Large Datasets into your Database You must have a tab-delimited text file (each field in a row is separated with a tab) that contains only the rows from one table. LOAD DATA LOCAL INFILE ‘filename’ INTO TABLE tablename (col1name, col2name,...);

Inserting Very Large Datasets into your Database (Continued) You can create a file like this with: SELECT col1name, col2name FROM tablename INTO OUTFILE ‘filename’; Example: SELECT * FROM organism INTO OUTFILE '/tmp/organism.txt';

Creating Users/Granting Privileges GRANT ALL ON trii.* TO IDENTIFIED BY ‘guestpwd’; ALL - privilege type trii.* - all tables in trii database guest - username localhost - machine user can connect from guestpwd - password FLUSH PRIVILEGES;

Loading Data from MS Excel We will discuss 2 ways to do this In both cases you should first save your Excel spreadsheet as a tab-delimited text file. Go to: File > Save As

Check the File!!! Excel might have saved the end line characters incorrectly. Check in vi. If the file has a bunch of “^M” characters we have to replace them. At the command prompt: >vi gene.txt In vi: :0,$s/^M/^M/g OR At the command prompt: >perl -pi -e ‘s/^M/\n/g’ gene.txt To get the ^M: hold control + v

Loading Data from MS Excel Option 1: If your spreadsheet corresponds to a table in your database exactly, then you can save the file as a tab- delimited text file in Excel and then use the SQL command “LOAD DATA LOCAL INFILE…” from before. LOAD DATA INFILE ‘gene.txt’ INTO TABLE gene (ensembl_gene_id, organism_id, name, locuslink, chromosome, chromo_start, chromo_end, description);

Loading Data from MS Excel Option 2: Option 2 (most common) If you need to put some Excel columns into one table and some into another use Perl to read in your tab-delimited text file, process your data, and insert it into the database. Remember Perl is great at parsing files!

Indexes Add an index on a column (or columns) that will be queried frequently (with an exact match query). If something is a primary key it is automatically indexed. To find out what indexes exist on a table: SHOW INDEX FROM tablename;

Indexes Create an index on 1 column: CREATE INDEX indexname ON tablename (columnname); This will make searches on borrower_id fast: CREATE INDEX borrower_index ON on_loan (borrower_id);

Indexes Create an index on 2 columns: CREATE INDEX indexname ON tablename (column1name, column2name); This will make queries on book_id fast, as well as queries on book_id and copy_id but NOT copy_id alone: CREATE INDEX book_index ON on_loan (book_id, copy_id);