Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MySQL Cheat Sheet


Published on

original MySQL cheat sheet created by Mikiya Okuno.
translated to English by Dominick Chen.

  • Be the first to comment

MySQL Cheat Sheet

  1. 1. MySQL Cheat Sheet.EN newest original japanese sheet available at: | MySQL Official Document: Use my.cnf for instance settings you can choose different Table Ops Command storage engine for each table connection List existing tables mysql> SHOW [FULL] TABLES; ....... threads Storage Engine Show table information mysql> SHOW TABLE STATUS [LIKE table1]; Query cache Optimizer Thread Cache Binary Log mysql> DESC table1; ... Check table properties mysql> SHOW CREATE TABLE table1 G db1 db2 Buffer Pool BG mysql> CREATE TABLE table1 [columns...] table1 table2 table3 ... table1 table2 ... threads Create table Disk I/O ENGINE=desired storage engine Modify table properties mysql> ALTER TABLE table1 ... Data File Log File Transaction Ops Command Storage Storage Storage Engine Engine Engine Switch off auto commit mysql> SET AUTOCOMMIT=0; mysql> START TRANSACTION; Start a transactionBasic Ops Command mysql> BEGIN; shell> mysql --version Execute SQL statement mysql> SELECT ... (any SQL statement)Check mysqld version mysql> SELECT VERSION; Commit mysql> COMMIT;Check set values shell> my_print_default_mysqld Place a save point mysql> SAVEPOINT name of save point;Show compile options shell> mysqlbug Rollback mysql> ROLLBACK;Connect to MySQL server shell> mysql -u user -p db1 Admin Ops CommandInstance Level Ops Command Export to a file mysql> SELECT ... INTO OUTFILE file name; shell> mysqld_safe & mysql> SET @@character_set_database=binary;Start mysqld shell> sudo /etc/init.d/mysqld start Read from a file mysql> LOAD DATA INFILE file name INTO shell> service mysqld start TABLE table name; shell> mysqladmin -uroot -p shutdown mysql> mysqldump [options] -B db1,db2 >Stop mysqld shell> sudo /etc/init.d/mysqld stop dump.sql shell> service mysqld stop Backup --single-transactions (snapshot using MVCC) --master-data=2 (output position of binary log) shell> mysqladmin -u root -p statusCheck status --flush-logs (switch binary logs) mysql> s Restore mysql> mysql db1 < dump.sqlShow system variables mysql> SHOW GLOBAL VARIABLES; Defrag mysql> OPTIMIZE TABLE table1;Show status variables mysql> SHOW GLOBAL STATUS; Update Statistics Info mysql> ANALYZE TABLE table1;List connected clients mysql> SHOW [FULL] PROCESSLIST; Switch logs mysql> FLUSH LOGS;Database Ops Command Export table mysql> FLUSH TABLES [WITH READ LOCK];List existing databases mysql> SHOW DATABASES;Create a database mysql> CREATE DATABASE db1; This work builds upon "MySQL Cheat Sheet" ( BY Mikiya Okuno, 2009, and is licensed under a Creative Commons: Attribution-ShareAlike liecense.Switch database to use mysql> USE db1; Translated to English by Dominick Chen, 2010.