open source database solution

Upload: tcdedios

Post on 07-Apr-2018

231 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/4/2019 Open Source Database Solution

    1/22

    Open Source Database Solution:

    mySQL

    Thomas Cagandahan de Dios

    IT Consultant

  • 8/4/2019 Open Source Database Solution

    2/22

    Outline

    Background of mySQL ANSI SQL Standards mySQL and other Databases

    Operating Systems Supported Connecting to and Disconnecting from the

    Server

    Creating and Using Database mySQL in Batch Mode Database Administration

  • 8/4/2019 Open Source Database Solution

    3/22

    Outline

    Column Data Types DDL (Data Definition Language) specifics mySQL Table Types

    mySQL ODBC Support Laboratory Exercise

  • 8/4/2019 Open Source Database Solution

    4/22

    Background of mySQL

    MySQL, the most popular Open Source SQLdatabase, is developed, distributed andsupported by MySQL AB.

    MySQL AB is a commercial company

    founded by the MySQL developers thatbuilds its business providing servicesaround the MySQL database

  • 8/4/2019 Open Source Database Solution

    5/22

    ANSI SQL Standards

    Entry-level SQL92. ODBC levels 0-3.51. Provides Extensions on SQL92

    Aims to achieve SQL-99

  • 8/4/2019 Open Source Database Solution

    6/22

    mySQL and other DatabasesProprietary Databases

    MS SQL Server Powersofts Sybase

    Oracle Informix NCRs TeradataOpen-Source Databases

    mySQL PostgreSQL mSQL

  • 8/4/2019 Open Source Database Solution

    7/22

    Operating Systems Supported

    AIX 4.x, 5.x with native threads. BSDI 2.x with the MIT-pthreads package. BSDI 3.0, 3.1 and 4.x with native threads. DEC Unix 4.x with native threads. FreeBSD 2.x with the MIT-pthreads package. FreeBSD 3.x and 4.x with native threads. HP-UX 10.20 with the DCE threads or the MIT-

    pthreads package.

    HP-UX 11.x with the native threads.

  • 8/4/2019 Open Source Database Solution

    8/22

    Operating Systems Supported

    Linux 2.0+ with LinuxThreads 0.7.1+ or glibc2.0.7+.

    Mac OS X. NetBSD 1.3/1.4 Intel and NetBSD 1.3 Alpha

    (Requires GNU make). OpenBSD > 2.5 with native threads. OpenBSD

    mysql> quit or exit (to disconnect)

  • 8/4/2019 Open Source Database Solution

    11/22

    Creating and Using Database

    To show databases in the servermysql> SHOW DATABASES;

    To use a database

    mysql> USE test; To create a new databasemysql> CREATE DATABASE tellim;

    To drop databasemysql> DROP DATABASE tellim;

  • 8/4/2019 Open Source Database Solution

    12/22

    Creating and Using Database

    To show tables in the databasemysql> SHOW TABLES;

    To create a new tablemysql> CREATE TABLE student

    (student_id VARCHAR(8),

    student_name VARCHAR(20),

    student_course VARCHAR(20));

    To show tables structuremysql> DESC student;

    To drop table

    mysql> DROP TABLE student;

  • 8/4/2019 Open Source Database Solution

    13/22

    mySQL in Batch Mode

    shell> mysql -h host -u user -p < batch-fileEnter password: ********

  • 8/4/2019 Open Source Database Solution

    14/22

    Database AdministrationGRANT priv_type [(column_list)] [, priv_type

    [(column_list)] ...] ON {tbl_name | * | *.* | db_name.*}TO user_name [IDENTIFIED BY [PASSWORD]'password'] [, user_name [IDENTIFIED BY 'password']...] [REQUIRE NONE | [{SSL| X509}] [CIPHER cipher

    [AND]] [ISSUER issuer [AND]] [SUBJECT subject]][WITH [GRANT OPTION | MAX_QUERIES_PER_HOUR #| MAX_UPDATES_PER_HOUR # |MAX_CONNECTIONS_PER_HOUR #]]

    REVOKE priv_type [(column_list)] [, priv_type[(column_list)] ...] ON {tbl_name | * | *.* | db_name.*}FROM user_name [, user_name ...]

    FLUSH PRIVILEGES

  • 8/4/2019 Open Source Database Solution

    15/22

    Column Data Types

    Numeric Types:NUMERIC (m, d)

    DECIMAL (m, d)

    INTEGER (n)SMALLINT (n)

    FLOAT (x)

    REAL (m, d)DOUBLE (m, d)

    Date and Time Types:DATETIME

    DATE

    TIMESTAMPTIME

    YEAR

    String types:

    CHAR

    VARCHAR

  • 8/4/2019 Open Source Database Solution

    16/22

    Data Definition LanguageCREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name

    [(create_definition,...)] [table_options][select_statement] or

    CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name

    LIKE old_table_name;

    create_definition: col_name type [NOT NULL | NULL] [DEFAULTdefault_value] [AUTO_INCREMENT] [PRIMARY KEY][reference_definition] or PRIMARY KEY (index_col_name,...) or KEY[index_name] (index_col_name,...) or INDEX [index_name](index_col_name,...) or UNIQUE [INDEX] [index_name](index_col_name,...) or FULLTEXT [INDEX] [index_name](index_col_name,...) or [CONSTRAINT symbol] FOREIGN KEY[index_name] (index_col_name,...) [reference_definition] or CHECK(expr)

  • 8/4/2019 Open Source Database Solution

    17/22

    Data Definition LanguageALTER [IGNORE] TABLE tbl_name alter_spec [, alter_spec ...]

    alter_specification: ADD [COLUMN] create_definition [FIRST | AFTERcolumn_name ] or ADD [COLUMN] (create_definition,create_definition,...) or ADD INDEX [index_name] (index_col_name,...)or ADD PRIMARY KEY (index_col_name,...) or ADD UNIQUE[index_name] (index_col_name,...) or ADD FULLTEXT [index_name](index_col_name,...) or ADD [CONSTRAINT symbol] FOREIGN KEY[index_name] (index_col_name,...) [reference_definition] or ALTER[COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT} orCHANGE [COLUMN] old_col_name create_definition [FIRST | AFTERcolumn_name] or MODIFY [COLUMN] create_definition [FIRST | AFTER

    column_name] or DROP [COLUMN] col_name or DROP PRIMARY KEY orDROP INDEX index_name or DISABLE KEYS or ENABLE KEYS or RENAME[TO] new_tbl_name or ORDER BY col or table_options

  • 8/4/2019 Open Source Database Solution

    18/22

    Data Definition Language

    RENAME TABLE tbl_name TO new_tbl_name[, tbl_name2 TO new_tbl_name2,...]

    DROP [TEMPORARY] TABLE [IF EXISTS] tbl_name [,tbl_name,...] [RESTRICT | CASCADE]

    CREATE [UNIQUE|FULLTEXT] INDEX index_nameON tbl_name (col_name[(length)],... )

    DROP INDEX index_name ON tbl_name

  • 8/4/2019 Open Source Database Solution

    19/22

    mySQL Table Types

    transaction-safe tables(InnoDB and BDB)

    not transaction-safe tables(HEAP, ISAM, MERGE, and MyISAM).

  • 8/4/2019 Open Source Database Solution

    20/22

    mySQL Table TypesAdvantages of transaction-safe tables (TST): Safer. Even if MySQL crashes or you get hardware

    problems, you can get your data back, either byautomatic recovery or from a backup + the transactionlog.

    You can combine many statements and accept these allin one go with the COMMIT command. You can execute ROLLBACK to ignore your changes (if

    you are not running in auto-commit mode). If an update fails, all your changes will be restored.

    (With NTST tables all changes that have taken place arepermanent)

    Can provide better concurrency if the table gets manyupdates concurrently with reads.

    Note that to use InnoDB tables you have to use at leastthe innodb_data_file_path startup option.

  • 8/4/2019 Open Source Database Solution

    21/22

    mySQL Table TypesAdvantages of not transaction-safe tables (NTST): Much faster as there is no transaction overhead. Will use less disk space as there is no overhead of

    transactions. Will use less memory to do updates.

  • 8/4/2019 Open Source Database Solution

    22/22

    For technical support

    and inquiries:[email protected]

    MAGIS DEI INFOTECH SOLUTIONS

    mailto:[email protected]:[email protected]