By George Reese
Price: $14.99 USD
£9.50 GBP
Cover | Table of Contents
ALTER TABLE that you generally never use, you can reach into your laptop case and grab this reference. As an experienced MySQL architect, administrator, or programmer, you can look to this reference.Constant widthALTER TABLE that you generally never use, you can reach into your laptop case and grab this reference. As an experienced MySQL architect, administrator, or programmer, you can look to this reference.Constant widthCREATE VIEW, DROP VIEW, and ALTER VIEW.CREATE TRIGGER and DROP TRIGGER.CREATE PROCEDUREALTER PROCEDUREDROP PROCEDURECALLBEGIN/ENDOPEN, FETCH, and CLOSE.password option specified on the command line, in your configuration file, and in an environment variable, the command-line option wins. shows a list of configuration options. Each option applies to one or more MySQL tools, depending on the context.Option | Description |
|---|---|
basedir=directory | Specifies the root directory of your MySQL installation. |
mysql --user=username
mysql -uusername
$ man -M/usr/local/mysql/man mysql
\g.[]) to indicate optional parts of the syntax. The following example shows how BIGINT is explained in this chapter:
BIGINT[(display_size)]
BIGINT alone or with a display size value. The italics indicate that you do not enter display_size literally, but instead enter your own value. Possible uses of BIGINT include:BIGINT BIGINT(20)
BIGINT type, many other MySQL data types support the specification of a display size. Unless otherwise specified, this value must be an integer between 1 and 255.VARCHAR → CHARVARCHAR column size is less than four characters, it is converted to CHAR.CHAR → VARCHARCHAR columns greater than three characters in length are converted to VARCHAR.TIMESTAMP display sizesTIMESTAMP fields must be an even value between 2 and 14. A display size of 0 or greater than 14 converts the field to a display size of 14. An odd-valued display size is converted to the next highest even value. MySQL 5 no longer takes a size value for timestamps.Token type | Case-sensitivity |
|---|---|
Keywords | Case-insensitive. |
Identifiers (databases and tables) | Dependent on the case-sensitivity for the underlying operating system. On all Unix systems except Mac OS X using HFS+, database and table names are case-sensitive. On Mac OS X using HFS+ and Windows, they are case-insensitive. |
Table aliases | Case-sensitive. |
Column aliases | Case-insensitive. |
'This is a ''quote'''
Escape sequence | Value |
|---|---|
\0 | NUL |
\' | Single quote |
\" | Double quote |
\b | Backspace |
\n | Newline |
\r | Carriage return |
\t | Tab |
\z | Ctrl-z (workaround for Windows use of Ctrl-z as EOF) |
\\ | Backslash |
\% | Percent sign (only in contexts where a percent sign would be interpreted as a wildcard) |
\_ | Underscore (only in contexts where an underscore would be interpreted as a wildcard) |
BINARY, COLLATE!- (unary minus) ~ (unary bit inversion)^* / % DIV MOD+ -<< >>&|< <= > >= = <=> <> IN IS LIKE REGEXPBETWEEN CASE WHEN THEN ELSENOT&& AND|| OR XOR:=+-*/DIV%|OR on two integer values.^OR on two integer values.&AND on two integer values.<<>><=> operator, NULL values cause a comparison operator to evaluate to NULL.<> or !=<=<>=>BETWEEN value1 AND value2NOT BETWEEN value1 AND value2IN (value1,value2,...)NOT IN (value1, value2,...)LIKE value2%', which matches any number of characters (including 0), and '_', which matches exactly one character. Its most common use is comparing a field value with a literal containing a wildcard (e.g., SELECT AVG(height) FROM kids would return the average of all the values of the height field in the kids table. AVG( ), COUNT( ), and SUM( ) allow DISTINCT.AVG(expression)SELECT AVG(score) FROM tests).BIT_AND(expression)AND aggregate of all the values in expression (e.g., SELECT BIT_AND(flags) FROM options). A bit will be set in the result if and only if the bit is set in every input field.BIT_OR(expression)OR aggregate of all the values in expression (e.g., SELECT BIT_OR(flags) FROM options). A bit is set in the result if it is set in at least one of the input fields.BIT_XOR(expression)XOR aggregate of all the values in expression with 64-bit precision.COUNT(expression)COUNT(*) will return the number of rows with some data in the entire table (e.g., SELECT COUNT(*) FROM folders).GROUP_CONCAT([DISTNCT] expression [ORDER BY {column | expression}] [SEPARATOR sep])MAX(expression)SELECT MAX (elevation) FROM mountains).MIN(expression)SELECT MIN(level) FROM toxic_waste).STDDEV_POP(expression)SELECT STDDEV_POP(points) FROM data). Also supported are the old MySQL STD( ) and the Oracle STDDEV( ) function, which both use the same syntax but are not portable. STDDEV_POP( ) is new standard SQL, provided as of MySQL 5.0.3.STDDEV_SAMP([expression])SUM(expression)SELECT SUM(calories) FROM daily_diet).VAR_POP(expression)Type | Transactional | Description |
|---|---|---|
ARCHIVE | No | Used for archiving databases without indexes in a very small footprint. |
BLACKHOLE | No | Stores no data at all. All queries return no rows. |
CSV | No | Stores data in comma-separated files. |
FALCON | Yes | New experimental, transactional storage engine to potentially replace InnoDB in a future release. |
INNODB | Yes | Transaction-safe tables with row locking. |
MEMORY (formerly HEAP) | No | Memory-based table; not persistent. |
MERGE | No | A collection of MyISAM tables merged as a single table. |
MYISAM | No | A newer, portable table type to replace ISAM. |
NDB | Yes | Clustered storage engine for MySQL Cluster. |
IN parameters; procedures can accept IN, OUT, and INOUT parameters.OUT or INOUT parameters.CALL command.CREATE PROCEDURE/CREATE FUNCTION command creates a stored procedure. You must have CREATE ROUTINE privileges in order to create any stored procedure in MySQL. You must define a name and a body for the procedure:CREATE PROCEDURE sitecount( ) SELECT COUNT(*) FROM web_site;
CALL command:CALL sitecount( );
IN parameter. Stored functions can accept only IN parameters.OUTINOUTINOUT parameter and any changes made by the procedure then become available to the caller after the procedure is executed.CREATE PROCEDURE sitecount(OUT total INT) SELECT COUNT(*) INTO total FROM web_site; CREATE PROCEDURE ssl_port(IN addr VARCHAR(255), OUT total INT) SELECT ssl_port INTO total FROM web_site WHERE address = addr;
CALL sitecount(@total);
SELECT @total;
CALL ssl_port('www.valtira.com', @port);
SELECT @port;
BEFORE or AFTER the event. The events on which you can build a trigger are:INSERTUPDATEDELETEBEGIN/END block. The main difference is that your logic is also bounded by a FOR EACH ROW section:DELIMITER // CREATE TRIGGER zap_addresses AFTER DELETE ON web_site FOR EACH ROW BEGIN DELETE FROM web_address WHERE web_site_id = OLD.web_site_id; END;
NEW and OLD reference the new and old row values, respectively.Return to MySQL Pocket Reference