Getting Started

Connect MySQL

mysql -u <user> -p
mysql [db\_name]
mysql -h <host> -P <port> -u <user> -p [db\_name]
mysql -h <host> -u <user> -p [db\_name]

Backups

Create a backup

mysqldump -u user -p db_name > db.sql

Export db without schema

mysqldump -u user -p db_name --no-data=true --add-drop-table=false > db.sql

Restore a backup

mysql -u user -p db_name < db.sql

Commons

#Database

- -
CREATE DATABASE db ; Create database
SHOW DATABASES; List databases
USE db; Switch to db
CONNECT db ; Switch to db
DROP DATABASE db; Delete db

#Table

- -
SHOW TABLES; List tables for current db
SHOW FIELDS FROM t; List fields for a table
DESC t; Show table structure
SHOW CREATE TABLE t; Show create table sql
TRUNCATE TABLE t; Remove all data in a table
DROP TABLE t; Delete table

#Proccess

- -
show processlist; List processes
kill pid; kill process

#Other

- -
exit or \q Exit MySQL session
Comments