This document provides a cheat sheet for MySQL with summaries of basic operations, table operations, storage engines, transaction operations, administration operations, and more. It includes commands for connecting to MySQL, starting and stopping the MySQL daemon, checking server status, creating and modifying databases and tables, importing and exporting data, and server administration tasks like backups, restores, and log maintenance. A link is provided to the original Japanese sheet as well as the MySQL official documentation.
1 of 1
Download to read offline
More Related Content
MySQL Cheat Sheet
1. MySQL Cheat Sheet.EN newest original japanese sheet available at: http://bit.ly/73I1bQ | MySQL Of?cial Document: http://dev.mysql.com/doc
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 Bu?er 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 transaction
Basic 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 Command
Instance Level Ops Command Export to a ?le mysql> SELECT ... INTO OUTFILE '?le name';
shell> mysqld_safe & mysql> SET @@character_set_database=binary;
Start mysqld shell> sudo /etc/init.d/mysqld start Read from a ?le mysql> LOAD DATA INFILE '?le 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 status
Check status --?ush-logs (switch binary logs)
mysql> s
Restore mysql> mysql db1 < dump.sql
Show 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" (http://bit.ly/73I1bQ) 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.