mysql cheat sheet

1

Click here to load reader

Upload: chen-dominique

Post on 21-May-2015

2.459 views

Category:

Documents


4 download

DESCRIPTION

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

TRANSCRIPT

Page 1: MySQL Cheat Sheet

StorageEngine

StorageEngine

StorageEngine

mysql> USE db1;

List connected clients

Show compile options

Basic Ops

Switch database to use

shell> mysqld_safe &shell> sudo /etc/init.d/mysqld startshell> service mysqld start

Command

Database Ops

Stop mysqld

Start mysqld

shell> my_print_default_mysqld

mysql> SHOW DATABASES;

Check status

mysql> SHOW [FULL] PROCESSLIST;

Check mysqld version

List existing databasesmysql> CREATE DATABASE db1;

Command

shell> mysqladmin -uroot -p shutdownshell> sudo /etc/init.d/mysqld stopshell> service mysqld stop

Instance Level Ops

Check set values

Commandshell> mysql -u user -p db1

shell> mysqladmin -u root -p statusmysql> \s

Connect to MySQL servershell> mysqlbug

mysql> SHOW GLOBAL VARIABLES;

shell> mysql --versionmysql> SELECT VERSION;

mysql> SHOW GLOBAL STATUS;Show status variablesShow system variables

Create a database

Restore

Commit

mysql> START TRANSACTION;mysql> BEGIN;

mysql> SHOW [FULL] TABLES;

Start a transaction

mysql> DESC table1;mysql> SHOW CREATE TABLE table1 \GCheck table properties

mysql> mysql db1 < dump.sql

mysql> SET AUTOCOMMIT=0;

mysql> ROLLBACK;

Switch logs

Place a save point

Backup

Rollback

mysql> FLUSH TABLES [WITH READ LOCK];

Command

Export table

mysql> ANALYZE TABLE table1;

Modify table properties

mysql> mysqldump [options] -B db1,db2 > dump.sql--single-transactions (snapshot using MVCC)--master-data=2 (output position of binary log)--flush-logs (switch binary logs)

mysql> SET @@character_set_database=binary;mysql> LOAD DATA INFILE 'file name' INTO TABLE 'table name';

List existing tables

mysql> OPTIMIZE TABLE table1;

Switch off auto commit

Table Ops

Read from a file

mysql> SELECT ... INTO OUTFILE 'file name';

Execute SQL statement

Show table information

Defrag

mysql> ALTER TABLE table1 ...

Command

Create table

Admin Ops

mysql> COMMIT;mysql> SELECT ... (any SQL statement)

mysql> SAVEPOINT name of save point;

Export to a file

Update Statistics Info

mysql> CREATE TABLE table1 [columns...] ENGINE=desired storage engine

Command

mysql> FLUSH LOGS;

mysql> SHOW TABLE STATUS [LIKE 'table1'];

Transaction Ops

Use my.cnf for instance settings

Query cache Optimizer Thread Cache Binary Log

db1 db2table1 table2 table3 table1 table2

connectionthreads

you can choose different storage engine for each table

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.Translated to English by Dominick Chen, 2010.

MySQL Cheat Sheet.EN MySQL Official Document: http://dev.mysql.com/doc

.......

... ...

Buffer Pool

Data File

BGthreads

Storage Engine

Disk I/O

...

Log File

newest original japanese sheet available at: http://bit.ly/73I1bQ |