SlideShare a Scribd company logo
Introduction to MySQL

●   Introduction
●   Installation
●   SQL
●   Schema design
●   Perl



BITS/VIB Bioinformatics Training – Jun 24, 2011 – Luc Ducazu <luc@daphnia.com>
BITS: Introduction to MySQL - Introduction and Installation
Introduction to MySQL

●   Introduction
●   Installation
●   SQL
●   Schema design
●   Perl




BITS/VIB Bioinformatics Training – Jun 24, 2011 – Luc Ducazu <luc@daphnia.com>
Databases
●   A database is a collection of data
    –   numbers
    –   dates
    –   text or labels
    –   …
●   A Database Management System
    –   Data storage
    –   Data retrieval
    –   Data manipulation
    –   Authentication & Authorization
Relational Databases
●   Rigid structure
●   2 dimensional tables: 
    –   columns (fields)
    –   rows (records)
Relational Databases
●   Model objects (entities) and their relationships
●   Eg a store sells products to customers
    –   Entities:
         ●   Customers
             Attributes: name, address, telephone number...
         ●   Products 
             Attributes: name, price...
    –   Relationships:
         ●   Sale
             Attributes: quantity, timestamp...
Relational Databases
●   MySQL Workbench:
    –   graphical representation of entities and relationships
    –   generates SQL statements to create database & tables
Relational Database Management 
           Systems (RDBMS)
●   Enforce data intergrity:
    Honors constraints on columns
●   Enforce referential integrity:
    Honors constraints on relations
●   See also: the 12 rules of Edgar Codd
    http://en.wikipedia.org/wiki/Codd%27s_12_rules
RDBMS
●   Commercial products:
    –   Oracle
    –   DB2 (IBM)
    –   MS SQL Server (Microsoft)
●   Open­source offerings:
    –   MySQL (Oracle)
        Forks:
         ●   MariaDB
         ●   Drizzle
    –   PostgreSQL
    –   SQLite
NoSQL
●   Key­value stores
    –   Berkeley DB
●   Document databases – unstructured data
    –   CouchDB
    –   MongoDB
    –   Cassandra (FaceBook)
●   See also: 
    http://en.wikipedia.org/wiki/Nosql
Introduction to MySQL

●   Introduction
●   Installation
●   SQL
●   Schema design
●   Perl




BITS/VIB Bioinformatics Training – Jun 24, 2011 – Luc Ducazu <luc@daphnia.com>
Installing MySQL on Linux
●   For DEB based Linux distributions
    (Debian, Ubuntu, …)
    # apt­get install mysql­server

●   For RPM based Linux distributions
    (RHEL, Fedora, CentOS, ...)
    # yum install mysql­server
Installing MySQL on Windows
●   An installable (MSI) package is available on the 
    MySQL site:
    http://www.mysql.com/
    –   Follow the 'Downloads (GA)' link
    –   Choose 'MySQL Community Server'
    –   Select 'Microsoft Windows' as platform
Running MySQL
●   To start / stop / restart the MySQL service:
    # service mysql start
    # service mysql stop
    # service mysql restart
●   When starting MySQL for the first time, the 
    system administrator is reminded that the MySQL 
    setup is not yet secured
Running MySQL
●   To check whether or not mysql is running 
    correctly:
    # service mysql status
    mysql start/running, process 3394

    # ps ­ef | grep mysql
    mysql  3394  1  0 12:09 ?  00:00:00  /usr/sbin/mysqld

    # netstat ­ltpn | grep mysql
    tcp 0 0  0.0.0.0:3306  0.0.0.0:*  LISTEN  3394/mysqld 
Exercises
●   Install MySQL
●   Start the service
●   Check whether or not the service has been started
The MySQL monitor
●   To connect or log on to a MySQL database 
    service:
    $ mysql
●   The MySQL monitor has many options, you can 
    review them using:
    $ man mysql
    or 
    $ mysql ­­help
The MySQL monitor
●   The most important options are:
    $ mysql [options] [database]
     ­u uname | ­­user=uname
      default: UNIX account
     ­p [pwd]| ­­password[=pwd]
      default: <none>
      if pwd not given, prompt for password
     ­h hname | ­­host=hname
      default: localhost
     ­P prt | ­­port=prt
      default: 3306
The MySQL monitor
●   Once connected to the database server, you can 
    execute SQL statements:
    mysql> statement;
●   Every SQL statement should end with a semi­
    colon (;)
Exercises
●   Make sure you do these exercises as a normal 
    UNIX user, and not as root.
●   Connect to the database and execute the 
    following SQL statements:
    mysql> select current_user;
    mysql> show databases;
●   Connect to the databases as user root and execute 
    the same statements.
●   Do you understand the (security) implications?
Securing the server
●   The process of securing the server is automated 
    by running the script
    # mysql_secure_installation
    as root:
    –   Changes the root password
    –   Removes anonymous users
    –   Disallows remote root logins
    –   Removes the test database
Securing the server
●   As an extra precaution, we will prevent any 
    external access to the database server. This is 
    done by putting the following line in the global 
    config file (/etc/mysql/my.cnf) (*):
    [mysqld]
    bind­address = 127.0.0.1
●   After restarting the MySQL service, verify with
    # netstat ­ltpn | grep mysql
    tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1228/mysqld

●   (*) On standard MySQL installations, the global 
    config file is /etc/my.cnf
Exercises
●   Secure your MySQL installation
●   Repeat the last exercise:
    –   it is no longer possible to log in with your ordinary 
        UNIX account ­ why ?
    –   you can still login as root, but with a twist...
Database Users
●   In principle, database users and OS users are 
    completely independent from each other:
    –   If no user is specified when executing mysql, 
        the OS user is taken
    –   The database superadmin is called root@localhost
        This user can do anything, including dropping 
        databases
●   It is not a good idea to always connect to the DB 
    as root. Try to log in as a less privileged user as 
    much as possible.
Database Users
●   To create a database user, connect to the database 
    server as root and issue the following statement:
    mysql> create user dbuser[@host]
           [identified by 'passwd'];
●   In this statement is:
    –   dbuser: the user to be created
    –   host: the hostname from which the user is going to 
        connect ­ if not specified the user can connect from 
        any host (%)
    –   passwd: the password needed to connect to the 
        database server
Exercises
●   Create a database user:
    –   the database user has the same name as your UNIX 
        account
    –   the hostname is localhost
    –   you are free to choose the password
●   Try to connect as this user and execute the 
    following SQL statements:
    mysql> select current_user;
    mysql> show databases;
The options file
●   To avoid having to type your password every 
    time you connect to the database service, you can 
    create an options file:
    –   the file name is .my.cnf
    –   this file is located in your home directory
    –   since it might contain a password, protect it from 
        preying eyes: mode 600
●   The format of .my.cnf is similar to Windows 
    ini­files: it contains key=value pairs in [sections]
●   In fact, the key=value pairs are provided as 
    (invisible) command line parameters
The options file
●   As an example, the password will be put in an 
    options file.
●   Looking at the command line parameters of 
    mysql (and almost all client applications), the 
    password can be provided as:
    $ mysql ­­password=pwd
●   The options file contents could look like this:
    [client]
    password=pwd
Exercises
●   Create an options file and put the password in
●   Make sure the options file is protected on the OS 
    level
●   Try to connect to the database without specifying 
    a password
Database User Privileges
●   The created user has very limited privileges. To 
    grant privileges prv on table tbl in database db, 
    you need to execute the following statement:
    mysql> grant prv on db.tbl 
                      to user@host;
●   Some convenient wild cards:
    –   To grant all privileges, specify all as prv
    –   To include all databases, specify * as db
    –   To include all tables, specify * as tbl
●   The given database and table names do not have 
    to exist (yet)
Getting Help
●   An extensive help system is available in the 
    MySQL monitor:
    mysql> help
    This gives an overview of commands you can use 
    to customize the output
●   You can get help on any function or statement:
    mysql> help contents
    This shows you the broad topics of available 
    help. You can drill down into any of these topics
Getting Help ­ Demo
●   How to get help for creating users:
    mysql> help
    mysql> help contents
    mysql> help account management
    mysql> help create user

●   How to use less as a pager:
    $ export PAGER=/usr/bin/less
    $ mysql
    mysql> pager
    PAGER set to '/usr/bin/less'

More Related Content

PDF
Java Linked List Tutorial | Edureka
PDF
JavaScript - Chapter 8 - Objects
PPT
Introduction to CSS
PPTX
INLINE FUNCTION IN C++
PPTX
Static keyword ppt
PDF
jQuery for beginners
PPTX
HTTP request and response
Java Linked List Tutorial | Edureka
JavaScript - Chapter 8 - Objects
Introduction to CSS
INLINE FUNCTION IN C++
Static keyword ppt
jQuery for beginners
HTTP request and response

What's hot (20)

PPT
JQuery introduction
PPTX
JSON: The Basics
PDF
javascript objects
PPS
Introduction to Mysql
PPT
JavaScript - An Introduction
PPT
detailed information about Pointers in c language
PPTX
Complete Lecture on Css presentation
PPTX
Database connectivity in python
PDF
Lab1-DB-Cassandra
PPTX
jQuery
PPTX
Java script
PPTX
Cascading style sheets (CSS-Web Technology)
PDF
Introduction to MySQL
PPT
Data structures using c
PDF
Python programming : Files
PPTX
A brief introduction to SQLite PPT
PPTX
classes and objects in C++
PPT
Primitive data types
PPT
SQLITE Android
JQuery introduction
JSON: The Basics
javascript objects
Introduction to Mysql
JavaScript - An Introduction
detailed information about Pointers in c language
Complete Lecture on Css presentation
Database connectivity in python
Lab1-DB-Cassandra
jQuery
Java script
Cascading style sheets (CSS-Web Technology)
Introduction to MySQL
Data structures using c
Python programming : Files
A brief introduction to SQLite PPT
classes and objects in C++
Primitive data types
SQLITE Android
Ad

Viewers also liked (8)

PPT
Mysql tutorial
PDF
Mysql tutorial
PPT
Mysql tutorial commands_part1
PPT
Mysql Introduction
PDF
BITS: Introduction to relational databases and MySQL - SQL
PPTX
MySQL Indexing - Best practices for MySQL 5.6
PDF
Mysql introduction
Mysql tutorial
Mysql tutorial
Mysql tutorial commands_part1
Mysql Introduction
BITS: Introduction to relational databases and MySQL - SQL
MySQL Indexing - Best practices for MySQL 5.6
Mysql introduction
Ad

Similar to BITS: Introduction to MySQL - Introduction and Installation (20)

PDF
Introduction Mysql
PDF
Mysql tutorial 5257
PPTX
MySQL DBA OCP 1Z0-883
PDF
Mysql tutorial
PDF
My S Q L Introduction for 1 day training
PDF
My sql introduction for Bestcom
PDF
MySQL Backup and Security Best Practices
PDF
Getting started with my sql
PDF
Welcome to MySQL
PDF
Percona Live '18 Tutorial: The Accidental DBA
PDF
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
PDF
My SQL 101
PDF
SULTHAN's PHP, MySQL & wordpress
ODP
Sql installation
DOC
Database Security Explained
PPT
My sql with querys
PPS
Linux17 MySQL_installation
PPT
Mysqlppt3510
Introduction Mysql
Mysql tutorial 5257
MySQL DBA OCP 1Z0-883
Mysql tutorial
My S Q L Introduction for 1 day training
My sql introduction for Bestcom
MySQL Backup and Security Best Practices
Getting started with my sql
Welcome to MySQL
Percona Live '18 Tutorial: The Accidental DBA
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
My SQL 101
SULTHAN's PHP, MySQL & wordpress
Sql installation
Database Security Explained
My sql with querys
Linux17 MySQL_installation
Mysqlppt3510

More from BITS (20)

PDF
RNA-seq for DE analysis: detecting differential expression - part 5
PDF
RNA-seq for DE analysis: extracting counts and QC - part 4
PDF
RNA-seq for DE analysis: the biology behind observed changes - part 6
PDF
RNA-seq: analysis of raw data and preprocessing - part 2
PDF
RNA-seq: general concept, goal and experimental design - part 1
PDF
RNA-seq: Mapping and quality control - part 3
PDF
Productivity tips - Introduction to linux for bioinformatics
PDF
Text mining on the command line - Introduction to linux for bioinformatics
PDF
The structure of Linux - Introduction to Linux for bioinformatics
PDF
Managing your data - Introduction to Linux for bioinformatics
PDF
Introduction to Linux for bioinformatics
PDF
BITS - Genevestigator to easily access transcriptomics data
PDF
BITS - Comparative genomics: the Contra tool
PDF
BITS - Comparative genomics on the genome level
PDF
BITS - Comparative genomics: gene family analysis
PDF
BITS - Introduction to comparative genomics
PDF
BITS - Protein inference from mass spectrometry data
PDF
BITS - Overview of sequence databases for mass spectrometry data analysis
PDF
BITS - Search engines for mass spec data
PDF
BITS - Introduction to proteomics
RNA-seq for DE analysis: detecting differential expression - part 5
RNA-seq for DE analysis: extracting counts and QC - part 4
RNA-seq for DE analysis: the biology behind observed changes - part 6
RNA-seq: analysis of raw data and preprocessing - part 2
RNA-seq: general concept, goal and experimental design - part 1
RNA-seq: Mapping and quality control - part 3
Productivity tips - 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
Managing your data - Introduction to Linux for bioinformatics
Introduction to Linux for bioinformatics
BITS - Genevestigator to easily access transcriptomics data
BITS - Comparative genomics: the Contra tool
BITS - Comparative genomics on the genome level
BITS - Comparative genomics: gene family analysis
BITS - Introduction to comparative genomics
BITS - Protein inference from mass spectrometry data
BITS - Overview of sequence databases for mass spectrometry data analysis
BITS - Search engines for mass spec data
BITS - Introduction to proteomics

Recently uploaded (20)

PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
RMMM.pdf make it easy to upload and study
PPTX
Cell Types and Its function , kingdom of life
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Lesson notes of climatology university.
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Insiders guide to clinical Medicine.pdf
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Institutional Correction lecture only . . .
PPTX
Cell Structure & Organelles in detailed.
PDF
Complications of Minimal Access Surgery at WLH
PDF
Pre independence Education in Inndia.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Microbial disease of the cardiovascular and lymphatic systems
Final Presentation General Medicine 03-08-2024.pptx
RMMM.pdf make it easy to upload and study
Cell Types and Its function , kingdom of life
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
Lesson notes of climatology university.
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Insiders guide to clinical Medicine.pdf
Basic Mud Logging Guide for educational purpose
Institutional Correction lecture only . . .
Cell Structure & Organelles in detailed.
Complications of Minimal Access Surgery at WLH
Pre independence Education in Inndia.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...

BITS: Introduction to MySQL - Introduction and Installation

  • 1. Introduction to MySQL ● Introduction ● Installation ● SQL ● Schema design ● Perl BITS/VIB Bioinformatics Training – Jun 24, 2011 – Luc Ducazu <luc@daphnia.com>
  • 3. Introduction to MySQL ● Introduction ● Installation ● SQL ● Schema design ● Perl BITS/VIB Bioinformatics Training – Jun 24, 2011 – Luc Ducazu <luc@daphnia.com>
  • 4. Databases ● A database is a collection of data – numbers – dates – text or labels – … ● A Database Management System – Data storage – Data retrieval – Data manipulation – Authentication & Authorization
  • 5. Relational Databases ● Rigid structure ● 2 dimensional tables:  – columns (fields) – rows (records)
  • 6. Relational Databases ● Model objects (entities) and their relationships ● Eg a store sells products to customers – Entities: ● Customers Attributes: name, address, telephone number... ● Products  Attributes: name, price... – Relationships: ● Sale Attributes: quantity, timestamp...
  • 7. Relational Databases ● MySQL Workbench: – graphical representation of entities and relationships – generates SQL statements to create database & tables
  • 8. Relational Database Management  Systems (RDBMS) ● Enforce data intergrity: Honors constraints on columns ● Enforce referential integrity: Honors constraints on relations ● See also: the 12 rules of Edgar Codd http://en.wikipedia.org/wiki/Codd%27s_12_rules
  • 9. RDBMS ● Commercial products: – Oracle – DB2 (IBM) – MS SQL Server (Microsoft) ● Open­source offerings: – MySQL (Oracle) Forks: ● MariaDB ● Drizzle – PostgreSQL – SQLite
  • 10. NoSQL ● Key­value stores – Berkeley DB ● Document databases – unstructured data – CouchDB – MongoDB – Cassandra (FaceBook) ● See also:  http://en.wikipedia.org/wiki/Nosql
  • 11. Introduction to MySQL ● Introduction ● Installation ● SQL ● Schema design ● Perl BITS/VIB Bioinformatics Training – Jun 24, 2011 – Luc Ducazu <luc@daphnia.com>
  • 12. Installing MySQL on Linux ● For DEB based Linux distributions (Debian, Ubuntu, …) # apt­get install mysql­server ● For RPM based Linux distributions (RHEL, Fedora, CentOS, ...) # yum install mysql­server
  • 13. Installing MySQL on Windows ● An installable (MSI) package is available on the  MySQL site: http://www.mysql.com/ – Follow the 'Downloads (GA)' link – Choose 'MySQL Community Server' – Select 'Microsoft Windows' as platform
  • 14. Running MySQL ● To start / stop / restart the MySQL service: # service mysql start # service mysql stop # service mysql restart ● When starting MySQL for the first time, the  system administrator is reminded that the MySQL  setup is not yet secured
  • 15. Running MySQL ● To check whether or not mysql is running  correctly: # service mysql status mysql start/running, process 3394 # ps ­ef | grep mysql mysql  3394  1  0 12:09 ?  00:00:00  /usr/sbin/mysqld # netstat ­ltpn | grep mysql tcp 0 0  0.0.0.0:3306  0.0.0.0:*  LISTEN  3394/mysqld 
  • 16. Exercises ● Install MySQL ● Start the service ● Check whether or not the service has been started
  • 17. The MySQL monitor ● To connect or log on to a MySQL database  service: $ mysql ● The MySQL monitor has many options, you can  review them using: $ man mysql or  $ mysql ­­help
  • 18. The MySQL monitor ● The most important options are: $ mysql [options] [database]  ­u uname | ­­user=uname default: UNIX account  ­p [pwd]| ­­password[=pwd] default: <none> if pwd not given, prompt for password  ­h hname | ­­host=hname default: localhost  ­P prt | ­­port=prt default: 3306
  • 19. The MySQL monitor ● Once connected to the database server, you can  execute SQL statements: mysql> statement; ● Every SQL statement should end with a semi­ colon (;)
  • 20. Exercises ● Make sure you do these exercises as a normal  UNIX user, and not as root. ● Connect to the database and execute the  following SQL statements: mysql> select current_user; mysql> show databases; ● Connect to the databases as user root and execute  the same statements. ● Do you understand the (security) implications?
  • 21. Securing the server ● The process of securing the server is automated  by running the script # mysql_secure_installation as root: – Changes the root password – Removes anonymous users – Disallows remote root logins – Removes the test database
  • 22. Securing the server ● As an extra precaution, we will prevent any  external access to the database server. This is  done by putting the following line in the global  config file (/etc/mysql/my.cnf) (*): [mysqld] bind­address = 127.0.0.1 ● After restarting the MySQL service, verify with # netstat ­ltpn | grep mysql tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1228/mysqld ● (*) On standard MySQL installations, the global  config file is /etc/my.cnf
  • 23. Exercises ● Secure your MySQL installation ● Repeat the last exercise: – it is no longer possible to log in with your ordinary  UNIX account ­ why ? – you can still login as root, but with a twist...
  • 24. Database Users ● In principle, database users and OS users are  completely independent from each other: – If no user is specified when executing mysql,  the OS user is taken – The database superadmin is called root@localhost This user can do anything, including dropping  databases ● It is not a good idea to always connect to the DB  as root. Try to log in as a less privileged user as  much as possible.
  • 25. Database Users ● To create a database user, connect to the database  server as root and issue the following statement: mysql> create user dbuser[@host]        [identified by 'passwd']; ● In this statement is: – dbuser: the user to be created – host: the hostname from which the user is going to  connect ­ if not specified the user can connect from  any host (%) – passwd: the password needed to connect to the  database server
  • 26. Exercises ● Create a database user: – the database user has the same name as your UNIX  account – the hostname is localhost – you are free to choose the password ● Try to connect as this user and execute the  following SQL statements: mysql> select current_user; mysql> show databases;
  • 27. The options file ● To avoid having to type your password every  time you connect to the database service, you can  create an options file: – the file name is .my.cnf – this file is located in your home directory – since it might contain a password, protect it from  preying eyes: mode 600 ● The format of .my.cnf is similar to Windows  ini­files: it contains key=value pairs in [sections] ● In fact, the key=value pairs are provided as  (invisible) command line parameters
  • 28. The options file ● As an example, the password will be put in an  options file. ● Looking at the command line parameters of  mysql (and almost all client applications), the  password can be provided as: $ mysql ­­password=pwd ● The options file contents could look like this: [client] password=pwd
  • 29. Exercises ● Create an options file and put the password in ● Make sure the options file is protected on the OS  level ● Try to connect to the database without specifying  a password
  • 30. Database User Privileges ● The created user has very limited privileges. To  grant privileges prv on table tbl in database db,  you need to execute the following statement: mysql> grant prv on db.tbl                    to user@host; ● Some convenient wild cards: – To grant all privileges, specify all as prv – To include all databases, specify * as db – To include all tables, specify * as tbl ● The given database and table names do not have  to exist (yet)
  • 31. Getting Help ● An extensive help system is available in the  MySQL monitor: mysql> help This gives an overview of commands you can use  to customize the output ● You can get help on any function or statement: mysql> help contents This shows you the broad topics of available  help. You can drill down into any of these topics
  • 32. Getting Help ­ Demo ● How to get help for creating users: mysql> help mysql> help contents mysql> help account management mysql> help create user ● How to use less as a pager: $ export PAGER=/usr/bin/less $ mysql mysql> pager PAGER set to '/usr/bin/less'