SlideShare a Scribd company logo
1 of 24
Download to read offline
Introduction to MySQL

●   Introduction
●   Installation
●   SQL
●   Schema design
●   Perl




BITS/VIB Bioinformatics Training – Jun 29, 2011 – Luc Ducazu <luc@daphnia.com>
Database schema
●   Although you can execute DDL commands from 
    the MySQL monitor directly, this is not often 
    done
●   There are tools that allow you to design a schema 
    graphically and generate the CREATE TABLE ... 
    statements 
●   Examples:
    –   MySQL workbench
    –   Dia
MySQL workbench
●   Available as a standard package on some Linux 
    distros (eg Fedora) 
●   Available as Windows MSI, Linux DEB or RPM 
    package or source archive from 
    http://dev.mysql.com/downloads/workbench/
●   To install a DEB package:
    # dpkg ­i package.deb
●   To install a RPM package:
    # rpm ­Uvh package.rpm
MySQL workbench ­ demo
Database schema
●   Once the schema is designed, MySQL workbench 
    can generate a 'script' containing all SQL 
    statements to create the tables and other objects:
    File ­> 
    Export ­> 
    Forward Engineer SQL CREATE Script
●   This 'script' can be executed as usual from the 
    MySQL monitor
Inserting rows
●   To populate tables, use the INSERT SQL 
    statement:
    mysql> insert into tbl
           (col1, col2, ...) 
           values
           (val1, val2, ...) [,
           (valx, valy, ...) , ...]
●   With:
    –   tbl the name of the table
    –   col1, col2, ... a list (subset) of column names
    –   val1 value for col1
    –   val2 value for col2
Inserting rows ­ examples
●   Example (biodb version 1)
    insert into modorg
    (id, class, genus, species,
     nchr, gsize, draft)
    values
    (1, “Bacteria”, “Escherichia”, “coli”,
     1, 4.639, “1997­09­05 00:00:00”)
●   Note that strings and dates have to be properly 
    quoted
Inserting rows
●   You can leave out the column list if
     – a value is given for all columns
     – the values are specified in the order dictated by the 
       schema
    mysql> insert into tbl
           values
           (val1, val2, ...) [,
           (valx, valy, ...) , ...]
Changing rows
●   To change one or more rows, use the UPDATE 
    SQL statement:
    mysql> update tbl
    set col1=expr1 [, col2=expr2, ...]
    [where cond]
●   With:
    –   tbl the name of the table
    –   col1 the column to change
    –   expr1 the new value 
    –   cond the row filter ­ if unspecified, all rows of the 
        table will be updated
Changing rows ­ examples
●   To change the C elegans number of 
    chromosomes to 7:
    update modorg
    set nchr = 7
    where genus = “caenorhabditis”
      and species = “elegans”;
●   To change the draft date to the current date:
    update modorg
    set draft = now();
Deleting rows
●   To remove rows, you use the DELETE SQL 
    statement:
    delete from tbl
    [where cond]
●   With:
    –   tbl the name of the table
    –   cond the row filter ­ if unspecified, all rows of the 
        table will be deleted
    –   note: since you can only remove entire rows, there is 
        no need to specify column names
Deleting rows ­ examples
●   To remove all in model organisms with a genome 
    publishing date before 2000:
    delete from modorg
    where year(draft) < 2000;
Introduction to MySQL

●   Introduction
●   Installation
●   SQL
●   Schema design
●   Perl



BITS/VIB Bioinformatics Training – Jun 29, 2011 – Luc Ducazu <luc@daphnia.com>
Perl
●   Perl is a scripting language that has excellent text 
    manipulation capabilities
●   Many biological 'databases' are available as flat 
    text files
●   Perl is very handy in the automation of the 
    population of MySQL databases
Automated population
●   There are basically two ways Perl can help to 
    insert data into tables:
    –   The Perl script generates USE, INSERT, ... SQL 
        statements. You can than execute these statements 
        using the MySQL monitor:
        $ perl myscript.pl | mysql
    –   The Perl script connects to the database and executes 
        SQL statements directly: DBI
Perl DBI
●   Perl DBI provides a programming interface that 
    abstracts most of the RDBMS specifics
●   In principle it should be possible to port scripts, 
    written for other RDBMS's (like PostgreSQL), to 
    MySQL with only minimal effort: all you have to 
    do is change the connection string
●   Packages to install (Ubuntu)
    –   libdbi­perl: Perl DBI
    –   libdbd­mysql­perl: MySQL driver for DBI
Perl DBI ­ connecting
●   Here is a minimal program:

    #!/usr/bin/perl ­w
    use strict;
    use DBI;

    my $dbh = DBI­>connect(
         “DBI:mysql:host=localhost;database=biodb”,
         “user”,
         “password”) or die;
    ...
    $dbh­>disconnect();
Perl DBI ­ connecting
●   Some highlights:
    –   use DBI;
        Load Perl DBI library
    –   DBI­>connect(connection string);
        Connect to a database
         ●   it is a MySQL database server
         ●   the DB server is running on the local machine
         ●   you can provide the name of the database
         ●   you can provide a user name and password
        The connect() function returns
         ●   a database handle ($dbh) on success
         ●   false on failure
    –   $dbh­>disconnect() to clean up resources
Perl DBI 
●   To execute a SQL statement that does not return a 
    result set, eg INSERT, DELETE, use do():
    my $n = $dbh­>do(stmt);
●   This function
    –   requires a valid database handle
    –   returns the number of rows affected, if no rows are 
        affected, a special value is returned: 0E0 (evaluates 
        true)
    –   false in case of an error
●   You can use execute() as well
Perl DBI 
●   To execute a SQL statement that returns a result 
    set, eg SELECT use the following recipe:
    1. Prepare a statement:
    my $sth = $dbh­>prepare(stmt);
    2. Send the query to the database server:
    $sth­>execute();
    3. Read the result, row by row:
    my @row = $sth­>fetchrow_array();
    my $ref = $sth­>fetchrow_hashref();
    4. Clean up resources:
    $sth­>finish();
Perl DBI ­ examples
●   To list all classes in modorg:
    ...
    my $qry = “select distinct class ”
            . “from modorg ” 
            . “order by class”;
    my $sth = $dbh­>prepare($qry);
    $sth­>execute();
    while(my @row = $sth­>fetchrow_array())
    {
       print “$row[0]n”;
    };
    $sth­>finish();
    ...
Perl DBI ­ examples
●   To list all organisms in modorg:
    ...
    my $qry = “select genus, species ”
            . “from modorg ” 
            . “order by genus”;
    my $sth = $dbh­>prepare($qry);
    $sth­>execute();
    while(my $ref = $sth­>fetchrow_hashref())
    {
       print $ref­>{“genus”} . “ “ 
           . $ref­>{“species”} . “n”;
    };
    $sth­>finish();
    ...
Perl DBI ­ examples
●   To insert a bunch of rows into modorg:
    ...
    my $qry = “insert into modorg ”
            . “(id, class, genus, species) ” 
            . “values (?, ?, ?, ?)”;

    my $sth = $dbh­>prepare($qry);
    $sth­>execute(11, “Mammels”, 
          “Sus”, “scrofa”);
    ...
Quoting
●   Never allow arbitrary user input in SQL 
    statements

More Related Content

What's hot

Scaling Databases with DBIx::Router
Scaling Databases with DBIx::RouterScaling Databases with DBIx::Router
Scaling Databases with DBIx::RouterPerrin Harkins
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programmingchhaichivon
 
Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Antony T Curtis
 
Using Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDBUsing Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDBAntony T Curtis
 
External Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLExternal Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLAntony T Curtis
 
Los Angeles R users group - Dec 14 2010 - Part 2
Los Angeles R users group - Dec 14 2010 - Part 2Los Angeles R users group - Dec 14 2010 - Part 2
Los Angeles R users group - Dec 14 2010 - Part 2rusersla
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slidesmetsarin
 
Database Connectivity in PHP
Database Connectivity in PHPDatabase Connectivity in PHP
Database Connectivity in PHPTaha Malampatti
 
Beginner guide to mysql command line
Beginner guide to mysql command lineBeginner guide to mysql command line
Beginner guide to mysql command linePriti Solanki
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database JonesJohn David Duncan
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012Roland Bouman
 
A brief introduction to PostgreSQL
A brief introduction to PostgreSQLA brief introduction to PostgreSQL
A brief introduction to PostgreSQLVu Hung Nguyen
 

What's hot (20)

PHP - Intriduction to MySQL And PHP
PHP - Intriduction to MySQL And PHPPHP - Intriduction to MySQL And PHP
PHP - Intriduction to MySQL And PHP
 
My sql administration
My sql administrationMy sql administration
My sql administration
 
Scaling Databases with DBIx::Router
Scaling Databases with DBIx::RouterScaling Databases with DBIx::Router
Scaling Databases with DBIx::Router
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programming
 
Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)
 
MySQL lecture
MySQL lectureMySQL lecture
MySQL lecture
 
Using Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDBUsing Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDB
 
Mysql Ppt
Mysql PptMysql Ppt
Mysql Ppt
 
External Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLExternal Language Stored Procedures for MySQL
External Language Stored Procedures for MySQL
 
Los Angeles R users group - Dec 14 2010 - Part 2
Los Angeles R users group - Dec 14 2010 - Part 2Los Angeles R users group - Dec 14 2010 - Part 2
Los Angeles R users group - Dec 14 2010 - Part 2
 
Mysql ppt
Mysql pptMysql ppt
Mysql ppt
 
Introduction to my_sql
Introduction to my_sqlIntroduction to my_sql
Introduction to my_sql
 
lab56_db
lab56_dblab56_db
lab56_db
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
 
Database Connectivity in PHP
Database Connectivity in PHPDatabase Connectivity in PHP
Database Connectivity in PHP
 
4.3 MySQL + PHP
4.3 MySQL + PHP4.3 MySQL + PHP
4.3 MySQL + PHP
 
Beginner guide to mysql command line
Beginner guide to mysql command lineBeginner guide to mysql command line
Beginner guide to mysql command line
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
A brief introduction to PostgreSQL
A brief introduction to PostgreSQLA brief introduction to PostgreSQL
A brief introduction to PostgreSQL
 

Viewers also liked

RNA-seq for DE analysis: extracting counts and QC - part 4
RNA-seq for DE analysis: extracting counts and QC - part 4RNA-seq for DE analysis: extracting counts and QC - part 4
RNA-seq for DE analysis: extracting counts and QC - part 4BITS
 
Eer >r.model
Eer >r.modelEer >r.model
Eer >r.modellavya3
 
Er & eer to relational mapping
Er & eer to relational mappingEr & eer to relational mapping
Er & eer to relational mappingsaurabhshertukde
 
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING ER DIAGRAM TO RELATIONAL SCHEMA MAPPING
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING ARADHYAYANA
 

Viewers also liked (6)

Relational Database Schema for MPEG 7 Visual Descriptors by Florian
Relational Database Schema for MPEG 7 Visual Descriptors by FlorianRelational Database Schema for MPEG 7 Visual Descriptors by Florian
Relational Database Schema for MPEG 7 Visual Descriptors by Florian
 
RNA-seq for DE analysis: extracting counts and QC - part 4
RNA-seq for DE analysis: extracting counts and QC - part 4RNA-seq for DE analysis: extracting counts and QC - part 4
RNA-seq for DE analysis: extracting counts and QC - part 4
 
Eer >r.model
Eer >r.modelEer >r.model
Eer >r.model
 
Er & eer to relational mapping
Er & eer to relational mappingEr & eer to relational mapping
Er & eer to relational mapping
 
Crj 3 1-b
Crj 3 1-bCrj 3 1-b
Crj 3 1-b
 
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING ER DIAGRAM TO RELATIONAL SCHEMA MAPPING
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING
 

Similar to BITS: Introduction to relational databases and MySQL - Schema design

SQL Server Select Topics
SQL Server Select TopicsSQL Server Select Topics
SQL Server Select TopicsJay Coskey
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in PerlLaurent Dami
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.pptMARasheed3
 
My sql with querys
My sql with querysMy sql with querys
My sql with querysNIRMAL FELIX
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL ISankhya_Analytics
 
Php classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbaiaadi Surve
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...Alex Zaballa
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...Alex Zaballa
 
DBIx-DataModel v2.0 in detail
DBIx-DataModel v2.0 in detail DBIx-DataModel v2.0 in detail
DBIx-DataModel v2.0 in detail Laurent Dami
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytWrushabhShirsat3
 
Getting Started with PL/Proxy
Getting Started with PL/ProxyGetting Started with PL/Proxy
Getting Started with PL/ProxyPeter Eisentraut
 
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuRedis Labs
 
Where's My SQL? Designing Databases with ActiveRecord Migrations
Where's My SQL? Designing Databases with ActiveRecord MigrationsWhere's My SQL? Designing Databases with ActiveRecord Migrations
Where's My SQL? Designing Databases with ActiveRecord MigrationsEleanor McHugh
 

Similar to BITS: Introduction to relational databases and MySQL - Schema design (20)

SQL Server Select Topics
SQL Server Select TopicsSQL Server Select Topics
SQL Server Select Topics
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in Perl
 
Mysql DBI
Mysql DBIMysql DBI
Mysql DBI
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.ppt
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
Sah
SahSah
Sah
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
 
MySQL for beginners
MySQL for beginnersMySQL for beginners
MySQL for beginners
 
Php classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbai
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
DBIx-DataModel v2.0 in detail
DBIx-DataModel v2.0 in detail DBIx-DataModel v2.0 in detail
DBIx-DataModel v2.0 in detail
 
My sql.ppt
My sql.pptMy sql.ppt
My sql.ppt
 
Working with databases
Working with databasesWorking with databases
Working with databases
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
 
unit-ii.pptx
unit-ii.pptxunit-ii.pptx
unit-ii.pptx
 
Getting Started with PL/Proxy
Getting Started with PL/ProxyGetting Started with PL/Proxy
Getting Started with PL/Proxy
 
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
Where's My SQL? Designing Databases with ActiveRecord Migrations
Where's My SQL? Designing Databases with ActiveRecord MigrationsWhere's My SQL? Designing Databases with ActiveRecord Migrations
Where's My SQL? Designing Databases with ActiveRecord Migrations
 

More from BITS

RNA-seq for DE analysis: detecting differential expression - part 5
RNA-seq for DE analysis: detecting differential expression - part 5RNA-seq for DE analysis: detecting differential expression - part 5
RNA-seq for DE analysis: detecting differential expression - part 5BITS
 
RNA-seq for DE analysis: the biology behind observed changes - part 6
RNA-seq for DE analysis: the biology behind observed changes - part 6RNA-seq for DE analysis: the biology behind observed changes - part 6
RNA-seq for DE analysis: the biology behind observed changes - part 6BITS
 
RNA-seq: analysis of raw data and preprocessing - part 2
RNA-seq: analysis of raw data and preprocessing - part 2RNA-seq: analysis of raw data and preprocessing - part 2
RNA-seq: analysis of raw data and preprocessing - part 2BITS
 
RNA-seq: general concept, goal and experimental design - part 1
RNA-seq: general concept, goal and experimental design - part 1RNA-seq: general concept, goal and experimental design - part 1
RNA-seq: general concept, goal and experimental design - part 1BITS
 
RNA-seq: Mapping and quality control - part 3
RNA-seq: Mapping and quality control - part 3RNA-seq: Mapping and quality control - part 3
RNA-seq: Mapping and quality control - part 3BITS
 
Productivity tips - Introduction to linux for bioinformatics
Productivity tips - Introduction to linux for bioinformaticsProductivity tips - Introduction to linux for bioinformatics
Productivity tips - Introduction to linux for bioinformaticsBITS
 
Text mining on the command line - Introduction to linux for bioinformatics
Text mining on the command line - Introduction to linux for bioinformaticsText mining on the command line - Introduction to linux for bioinformatics
Text mining on the command line - Introduction to linux for bioinformaticsBITS
 
The structure of Linux - Introduction to Linux for bioinformatics
The structure of Linux - Introduction to Linux for bioinformaticsThe structure of Linux - Introduction to Linux for bioinformatics
The structure of Linux - Introduction to Linux for bioinformaticsBITS
 
Managing your data - Introduction to Linux for bioinformatics
Managing your data - Introduction to Linux for bioinformaticsManaging your data - Introduction to Linux for bioinformatics
Managing your data - Introduction to Linux for bioinformaticsBITS
 
Introduction to Linux for bioinformatics
Introduction to Linux for bioinformaticsIntroduction to Linux for bioinformatics
Introduction to Linux for bioinformaticsBITS
 
BITS - Genevestigator to easily access transcriptomics data
BITS - Genevestigator to easily access transcriptomics dataBITS - Genevestigator to easily access transcriptomics data
BITS - Genevestigator to easily access transcriptomics dataBITS
 
BITS - Comparative genomics: the Contra tool
BITS - Comparative genomics: the Contra toolBITS - Comparative genomics: the Contra tool
BITS - Comparative genomics: the Contra toolBITS
 
BITS - Comparative genomics on the genome level
BITS - Comparative genomics on the genome levelBITS - Comparative genomics on the genome level
BITS - Comparative genomics on the genome levelBITS
 
BITS - Comparative genomics: gene family analysis
BITS - Comparative genomics: gene family analysisBITS - Comparative genomics: gene family analysis
BITS - Comparative genomics: gene family analysisBITS
 
BITS - Introduction to comparative genomics
BITS - Introduction to comparative genomicsBITS - Introduction to comparative genomics
BITS - Introduction to comparative genomicsBITS
 
BITS - Protein inference from mass spectrometry data
BITS - Protein inference from mass spectrometry dataBITS - Protein inference from mass spectrometry data
BITS - Protein inference from mass spectrometry dataBITS
 
BITS - Overview of sequence databases for mass spectrometry data analysis
BITS - Overview of sequence databases for mass spectrometry data analysisBITS - Overview of sequence databases for mass spectrometry data analysis
BITS - Overview of sequence databases for mass spectrometry data analysisBITS
 
BITS - Search engines for mass spec data
BITS - Search engines for mass spec dataBITS - Search engines for mass spec data
BITS - Search engines for mass spec dataBITS
 
BITS - Introduction to proteomics
BITS - Introduction to proteomicsBITS - Introduction to proteomics
BITS - Introduction to proteomicsBITS
 
BITS - Introduction to Mass Spec data generation
BITS - Introduction to Mass Spec data generationBITS - Introduction to Mass Spec data generation
BITS - Introduction to Mass Spec data generationBITS
 

More from BITS (20)

RNA-seq for DE analysis: detecting differential expression - part 5
RNA-seq for DE analysis: detecting differential expression - part 5RNA-seq for DE analysis: detecting differential expression - part 5
RNA-seq for DE analysis: detecting differential expression - part 5
 
RNA-seq for DE analysis: the biology behind observed changes - part 6
RNA-seq for DE analysis: the biology behind observed changes - part 6RNA-seq for DE analysis: the biology behind observed changes - part 6
RNA-seq for DE analysis: the biology behind observed changes - part 6
 
RNA-seq: analysis of raw data and preprocessing - part 2
RNA-seq: analysis of raw data and preprocessing - part 2RNA-seq: analysis of raw data and preprocessing - part 2
RNA-seq: analysis of raw data and preprocessing - part 2
 
RNA-seq: general concept, goal and experimental design - part 1
RNA-seq: general concept, goal and experimental design - part 1RNA-seq: general concept, goal and experimental design - part 1
RNA-seq: general concept, goal and experimental design - part 1
 
RNA-seq: Mapping and quality control - part 3
RNA-seq: Mapping and quality control - part 3RNA-seq: Mapping and quality control - part 3
RNA-seq: Mapping and quality control - part 3
 
Productivity tips - Introduction to linux for bioinformatics
Productivity tips - Introduction to linux for bioinformaticsProductivity tips - Introduction to linux for bioinformatics
Productivity tips - Introduction to linux for bioinformatics
 
Text mining on the command line - Introduction to linux for bioinformatics
Text mining on the command line - Introduction to linux for bioinformaticsText mining on the command line - Introduction to linux for bioinformatics
Text mining on the command line - Introduction to linux for bioinformatics
 
The structure of Linux - Introduction to Linux for bioinformatics
The structure of Linux - Introduction to Linux for bioinformaticsThe structure of Linux - Introduction to Linux for bioinformatics
The structure of Linux - Introduction to Linux for bioinformatics
 
Managing your data - Introduction to Linux for bioinformatics
Managing your data - Introduction to Linux for bioinformaticsManaging your data - Introduction to Linux for bioinformatics
Managing your data - Introduction to Linux for bioinformatics
 
Introduction to Linux for bioinformatics
Introduction to Linux for bioinformaticsIntroduction to Linux for bioinformatics
Introduction to Linux for bioinformatics
 
BITS - Genevestigator to easily access transcriptomics data
BITS - Genevestigator to easily access transcriptomics dataBITS - Genevestigator to easily access transcriptomics data
BITS - Genevestigator to easily access transcriptomics data
 
BITS - Comparative genomics: the Contra tool
BITS - Comparative genomics: the Contra toolBITS - Comparative genomics: the Contra tool
BITS - Comparative genomics: the Contra tool
 
BITS - Comparative genomics on the genome level
BITS - Comparative genomics on the genome levelBITS - Comparative genomics on the genome level
BITS - Comparative genomics on the genome level
 
BITS - Comparative genomics: gene family analysis
BITS - Comparative genomics: gene family analysisBITS - Comparative genomics: gene family analysis
BITS - Comparative genomics: gene family analysis
 
BITS - Introduction to comparative genomics
BITS - Introduction to comparative genomicsBITS - Introduction to comparative genomics
BITS - Introduction to comparative genomics
 
BITS - Protein inference from mass spectrometry data
BITS - Protein inference from mass spectrometry dataBITS - Protein inference from mass spectrometry data
BITS - Protein inference from mass spectrometry data
 
BITS - Overview of sequence databases for mass spectrometry data analysis
BITS - Overview of sequence databases for mass spectrometry data analysisBITS - Overview of sequence databases for mass spectrometry data analysis
BITS - Overview of sequence databases for mass spectrometry data analysis
 
BITS - Search engines for mass spec data
BITS - Search engines for mass spec dataBITS - Search engines for mass spec data
BITS - Search engines for mass spec data
 
BITS - Introduction to proteomics
BITS - Introduction to proteomicsBITS - Introduction to proteomics
BITS - Introduction to proteomics
 
BITS - Introduction to Mass Spec data generation
BITS - Introduction to Mass Spec data generationBITS - Introduction to Mass Spec data generation
BITS - Introduction to Mass Spec data generation
 

Recently uploaded

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 

Recently uploaded (20)

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 

BITS: Introduction to relational databases and MySQL - Schema design

  • 1. Introduction to MySQL ● Introduction ● Installation ● SQL ● Schema design ● Perl BITS/VIB Bioinformatics Training – Jun 29, 2011 – Luc Ducazu <luc@daphnia.com>
  • 2. Database schema ● Although you can execute DDL commands from  the MySQL monitor directly, this is not often  done ● There are tools that allow you to design a schema  graphically and generate the CREATE TABLE ...  statements  ● Examples: – MySQL workbench – Dia
  • 3. MySQL workbench ● Available as a standard package on some Linux  distros (eg Fedora)  ● Available as Windows MSI, Linux DEB or RPM  package or source archive from  http://dev.mysql.com/downloads/workbench/ ● To install a DEB package: # dpkg ­i package.deb ● To install a RPM package: # rpm ­Uvh package.rpm
  • 5. Database schema ● Once the schema is designed, MySQL workbench  can generate a 'script' containing all SQL  statements to create the tables and other objects: File ­>  Export ­>  Forward Engineer SQL CREATE Script ● This 'script' can be executed as usual from the  MySQL monitor
  • 6. Inserting rows ● To populate tables, use the INSERT SQL  statement: mysql> insert into tbl        (col1, col2, ...)         values        (val1, val2, ...) [,        (valx, valy, ...) , ...] ● With: – tbl the name of the table – col1, col2, ... a list (subset) of column names – val1 value for col1 – val2 value for col2
  • 7. Inserting rows ­ examples ● Example (biodb version 1) insert into modorg (id, class, genus, species,  nchr, gsize, draft) values (1, “Bacteria”, “Escherichia”, “coli”,  1, 4.639, “1997­09­05 00:00:00”) ● Note that strings and dates have to be properly  quoted
  • 8. Inserting rows ● You can leave out the column list if – a value is given for all columns – the values are specified in the order dictated by the  schema mysql> insert into tbl        values        (val1, val2, ...) [,        (valx, valy, ...) , ...]
  • 9. Changing rows ● To change one or more rows, use the UPDATE  SQL statement: mysql> update tbl set col1=expr1 [, col2=expr2, ...] [where cond] ● With: – tbl the name of the table – col1 the column to change – expr1 the new value  – cond the row filter ­ if unspecified, all rows of the  table will be updated
  • 10. Changing rows ­ examples ● To change the C elegans number of  chromosomes to 7: update modorg set nchr = 7 where genus = “caenorhabditis”   and species = “elegans”; ● To change the draft date to the current date: update modorg set draft = now();
  • 11. Deleting rows ● To remove rows, you use the DELETE SQL  statement: delete from tbl [where cond] ● With: – tbl the name of the table – cond the row filter ­ if unspecified, all rows of the  table will be deleted – note: since you can only remove entire rows, there is  no need to specify column names
  • 12. Deleting rows ­ examples ● To remove all in model organisms with a genome  publishing date before 2000: delete from modorg where year(draft) < 2000;
  • 13. Introduction to MySQL ● Introduction ● Installation ● SQL ● Schema design ● Perl BITS/VIB Bioinformatics Training – Jun 29, 2011 – Luc Ducazu <luc@daphnia.com>
  • 14. Perl ● Perl is a scripting language that has excellent text  manipulation capabilities ● Many biological 'databases' are available as flat  text files ● Perl is very handy in the automation of the  population of MySQL databases
  • 15. Automated population ● There are basically two ways Perl can help to  insert data into tables: – The Perl script generates USE, INSERT, ... SQL  statements. You can than execute these statements  using the MySQL monitor: $ perl myscript.pl | mysql – The Perl script connects to the database and executes  SQL statements directly: DBI
  • 16. Perl DBI ● Perl DBI provides a programming interface that  abstracts most of the RDBMS specifics ● In principle it should be possible to port scripts,  written for other RDBMS's (like PostgreSQL), to  MySQL with only minimal effort: all you have to  do is change the connection string ● Packages to install (Ubuntu) – libdbi­perl: Perl DBI – libdbd­mysql­perl: MySQL driver for DBI
  • 17. Perl DBI ­ connecting ● Here is a minimal program: #!/usr/bin/perl ­w use strict; use DBI; my $dbh = DBI­>connect(      “DBI:mysql:host=localhost;database=biodb”,      “user”,      “password”) or die; ... $dbh­>disconnect();
  • 18. Perl DBI ­ connecting ● Some highlights: – use DBI; Load Perl DBI library – DBI­>connect(connection string); Connect to a database ● it is a MySQL database server ● the DB server is running on the local machine ● you can provide the name of the database ● you can provide a user name and password The connect() function returns ● a database handle ($dbh) on success ● false on failure – $dbh­>disconnect() to clean up resources
  • 19. Perl DBI  ● To execute a SQL statement that does not return a  result set, eg INSERT, DELETE, use do(): my $n = $dbh­>do(stmt); ● This function – requires a valid database handle – returns the number of rows affected, if no rows are  affected, a special value is returned: 0E0 (evaluates  true) – false in case of an error ● You can use execute() as well
  • 20. Perl DBI  ● To execute a SQL statement that returns a result  set, eg SELECT use the following recipe: 1. Prepare a statement: my $sth = $dbh­>prepare(stmt); 2. Send the query to the database server: $sth­>execute(); 3. Read the result, row by row: my @row = $sth­>fetchrow_array(); my $ref = $sth­>fetchrow_hashref(); 4. Clean up resources: $sth­>finish();
  • 21. Perl DBI ­ examples ● To list all classes in modorg: ... my $qry = “select distinct class ”         . “from modorg ”          . “order by class”; my $sth = $dbh­>prepare($qry); $sth­>execute(); while(my @row = $sth­>fetchrow_array()) {    print “$row[0]n”; }; $sth­>finish(); ...
  • 22. Perl DBI ­ examples ● To list all organisms in modorg: ... my $qry = “select genus, species ”         . “from modorg ”          . “order by genus”; my $sth = $dbh­>prepare($qry); $sth­>execute(); while(my $ref = $sth­>fetchrow_hashref()) {    print $ref­>{“genus”} . “ “         . $ref­>{“species”} . “n”; }; $sth­>finish(); ...
  • 23. Perl DBI ­ examples ● To insert a bunch of rows into modorg: ... my $qry = “insert into modorg ”         . “(id, class, genus, species) ”          . “values (?, ?, ?, ?)”; my $sth = $dbh­>prepare($qry); $sth­>execute(11, “Mammels”,        “Sus”, “scrofa”); ...
  • 24. Quoting ● Never allow arbitrary user input in SQL  statements