MySQL Cheat Sheet
Table of Contents:
General
Host value examples: localhost, %, 127.0.0.1, %.example.com, 192.168.1.%, 192.168.1.0/255.255.255.0.
Create database
Users, privileges
List users
Add a user
Remove a user
As of MySQL 5.1+ it will remove privileges as well.
Show privileges
Grant privileges
Revoke privileges
Privileges list
- data: SELECT, INSERT, UPDATE, DELETE, FILE
- structure: CREATE, ALTER, INDEX, DROP, CREATE TEMPORARY TABLES, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EXECUTE, CREATE VIEW, EVENT, TRIGGER
- administration: GRANT, SUPER, PROCESS, RELOAD, SHUTDOWN, SHOW DATABASES, LOCK TABLES, REFERENCES, REPLICATION CLIENT, REPLICATION SLAVE, CREATE USER
TOC
Table structure
Create table
Copy table structure
Rename table
Remove table
TOC
Relations
Show relations
Add relation
Remove relation
TOC
Misc
Show MySQL version
Foreign key check
Reset auto increment
Concatenate (non NULL) values from a group
Search & Replace Data
Find duplicate records by a specific column
Delete duplicate records, but leave one
Troubleshooting
Disable cache
Per query
Per session, use 0 to turn OFF, 1 to turn ON. Accepted <level> values: 0, 1, 2.
Globally
Backup/Restore
Duplicate index check
Use pt-duplicate-key-checker from Percona Toolkit (documentation).
Finding out largest tables on MySQL Server
TOC
Resources
TOC