Sunteți pe pagina 1din 22

Open Source Database Solution: mySQL

Thomas Cagandahan de Dios IT Consultant

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

Outline

Column Data Types DDL (Data Definition Language) specifics mySQL Table Types mySQL ODBC Support Laboratory Exercise

Background of mySQL
MySQL, the most popular Open Source SQL database, is developed, distributed and supported by MySQL AB. MySQL AB is a commercial company founded by the MySQL developers that builds its business providing services around the MySQL database

ANSI SQL Standards


Entry-level SQL92. ODBC levels 0-3.51. Provides Extensions on SQL92 Aims to achieve SQL-99

mySQL and other Databases


Proprietary Databases MS SQL Server Powersofts Sybase Oracle Informix NCRs Teradata Open-Source Databases mySQL PostgreSQL mSQL

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 MITpthreads package. HP-UX 11.x with the native threads.

Operating Systems Supported


Linux 2.0+ with LinuxThreads 0.7.1+ or glibc
2.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 < 2.5 with the MIT-pthreads package. OS/2 Warp 3, FixPack 29 and OS/2 Warp 4, FixPack 4. SGI Irix 6.x with native threads. Solaris 2.5 and above with native threads on SPARC and x86.

Operating Systems Supported


SunOS 4.x with the MIT-pthreads package. Caldera (SCO) OpenServer with a recent port of
the FSU Pthreads package. Caldera (SCO) UnixWare 7.0.1. Tru64 Unix Windows 9x, Me, NT, 2000 and XP.

Connecting and Disconnecting


C:\mysql\bin\ mysql -h host -u user -p Enter password: ******** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 459 to server version: 3.22.20a-log Type 'help' for help. mysql> mysql> quit or exit (to disconnect)

Creating and Using Database


To show databases in the server
mysql> SHOW DATABASES; To use a database mysql> USE test; To create a new database mysql> CREATE DATABASE tellim; To drop database mysql> DROP DATABASE tellim;

To show tables in the database

Creating and Using Database

mysql> SHOW TABLES; To create a new table mysql> CREATE TABLE student (student_id VARCHAR(8), student_name VARCHAR(20), student_course VARCHAR(20)); To show tables structure mysql> DESC student; To drop table mysql> DROP TABLE student;

mySQL in Batch Mode


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

Database Administration
GRANT 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

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 TIMESTAMP TIME YEAR

String types: CHAR VARCHAR

Data Definition Language


CREATE [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] [DEFAULT default_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)

Data Definition Language


ALTER [IGNORE] TABLE tbl_name alter_spec [, alter_spec ...]
alter_specification: ADD [COLUMN] create_definition [FIRST | AFTER column_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} or CHANGE [COLUMN] old_col_name create_definition [FIRST | AFTER column_name] or MODIFY [COLUMN] create_definition [FIRST | AFTER column_name] or DROP [COLUMN] col_name or DROP PRIMARY KEY or DROP INDEX index_name or DISABLE KEYS or ENABLE KEYS or RENAME [TO] new_tbl_name or ORDER BY col or table_options

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_name ON tbl_name (col_name[(length)],... )

DROP INDEX index_name ON tbl_name

mySQL Table Types


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

mySQL Table Types


Advantages of transaction-safe tables (TST): Safer. Even if MySQL crashes or you get hardware problems, you can get your data back, either by automatic recovery or from a backup + the transaction log. You can combine many statements and accept these all in 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 are permanent) Can provide better concurrency if the table gets many updates concurrently with reads. Note that to use InnoDB tables you have to use at least the innodb_data_file_path startup option.

mySQL Table Types


Advantages 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.

For technical support and inquiries:


magis_dei@yahoo.com MAGIS DEI INFOTECH SOLUTIONS

S-ar putea să vă placă și