Professional Documents
Culture Documents
org/wiki/MySQL/CheatSheet
MySQL/CheatSheet
From Wikibooks, the open-content textbooks collection
Query
Conditionals
field1 = value1
field1 <> value1
field1 LIKE 'value _ %'
field1 IS NULL
field1 IS NOT NULL
field1 IS IN (value1, value2)
field1 IS NOT IN (value1, value2)
condition1 AND condition2
condition1 OR condition2
Data Manipulation
1 de 6 21/09/10 13:29
MySQL/CheatSheet - Wikibooks, collection of open... http://en.wikibooks.org/wiki/MySQL/CheatSheet
INSERT INTO table1 (field1, field2, ...) VALUES (value1, value2, ...)
INSERT table1 SET field1=value_1, field2=value_2 ...
Browsing
SHOW DATABASES
SHOW TABLES
SHOW FIELDS FROM table / SHOW COLUMNS FROM table / DESCRIBE table / DESC table /
SHOW CREATE TABLE table
SHOW PROCESSLIST
KILL process_number
$ mysqlshow
$ mysqlshow database
CREATE DATABASE [IF NOT EXIST] mabase [CHARACTER SET charset] [COLLATE collation
CREATE DATABASE mabase CHARACTER SET utf8
DROP DATABASE mabase
USE mabase
2 de 6 21/09/10 13:29
MySQL/CheatSheet - Wikibooks, collection of open... http://en.wikibooks.org/wiki/MySQL/CheatSheet
Create/delete/modify table
3 de 6 21/09/10 13:29
MySQL/CheatSheet - Wikibooks, collection of open... http://en.wikibooks.org/wiki/MySQL/CheatSheet
Keys
Privileges
4 de 6 21/09/10 13:29
MySQL/CheatSheet - Wikibooks, collection of open... http://en.wikibooks.org/wiki/MySQL/CheatSheet
TIME (HH:MM) YEAR (AAAA) DATE (AAAA-MM-JJ) DATETIME (AAAA-MM-JJ HH:MM; années 10
TIMESTAMP (like DATETIME, but 1970->2038, compatible with Unix)
$ /etc/init.d/mysql stop
$ mysqld_safe --skip-grant-tables
$ mysql # on another terminal
mysql> UPDATE mysql.user SET password=PASSWORD('nouveau') WHERE user='root';
## Kill mysqld_safe from the terminal, using Control + \
$ /etc/init.d/mysql start
5 de 6 21/09/10 13:29
MySQL/CheatSheet - Wikibooks, collection of open... http://en.wikibooks.org/wiki/MySQL/CheatSheet
mysqlcheck --all-databases
mysqlcheck --all-databases --fast
6 de 6 21/09/10 13:29