Slide MySql
Slide MySql
Slide MySql
Introduction to MySql y q
Slides by Ing. Carmelo Riggio
Overview
Main M i component: t MySQL Community Server Other components and utilities (all downloadable from www.mysql.com) MySQL Workbench (GUI tool) MySQL Query Analyzer MySQL Enterprise MySQL Embedded MySQL Data Warehouse MySQL Cluster MySQL Connectors MySQL Control Center (http://sourceforge.net/projects/mysqlcc )
Installation
Download and install M S C MySql Community Server . S For Windows download a MSI Installer and launch. g y During installation it will be necessary to set a password for the root user For Linux Ubuntu end other Debian based distribution execute apt-get install mysql from shell with root apt get mysql privileges.
First steps
Enter the password set during installation
USE command
After you create the database, you must select it with the USE command and display tables with "VIEW TABLES;"
Numeric modifiers
Automatically increases the value of a column by adding 1 to the maximum value.should be used in combination with NOT NULL It can be applied to all types integers NULL. integers.
Auto_increment : Unsigned:
values
ZEROFILL:
is used to insert a number preceded by a variable amount of zeros on the basis of the scale of the column. If for example you declare an INT field (10) ZEROFILL and you want to store the value "1234", it will be saved as "0000001234"
Others modifier
BINARY - Can be used with CHAR or VARCHAR DEFAULT - Can be used with all types of data (including digital ones) except TEXT and BLOB.Specifies the default value of the field. NULL / NOT NULL - Can be used with all types of data (numeric and string) PRIMARY KEY - Can be used with all types of data ( (numeric and string) g) UNIQUE - Can be used with all types of data (numeric and string).
Date functions
NOW():AAAA-MM-GG HH:MM:SS CURDATE():AAAAA-MM-GG CURTIME()HH:MM:SS DATE_ADD()DATE_ADD(date, INTERVAL expression type) DATE_SUB()DATE_SUBB(date, INTERVAL expression type) PERIOD_ADD()PERIOD_ADD(Period, Months) (the period is expressed as AAAAMM or AAMM) PERIOD_SUBB()PERIOD_SUB(Period_1, Period_2) (the period is expressed as AAAAMM oppure AAMM)
Some example
Sum 30 days to the current date: SELECT DATE_ADD(CURDATE(),INTERVAL 30 DAYS); Sub 3 months by a specific date: SELECT DATE_SUB('2009-01-13',INTERVAL 3 MONTHS); Add 7 months to January 2009 : h J 2 SELECT PERIOD_ADD(200901,7); Sub S b 7 months to J h January 2009 : SELECT PERIOD_ADD(200901,-7); Find h diff Fi d the difference (in months) between Jan 2009 and Oct 2005: (i h )b J d O 2005 SELECT PERIOD_SUB(200901,200510);