· 7 years ago · Oct 09, 2018, 01:54 PM
1Access MySQL server from the mysql client using a username and password (MySQL will prompt for a password):
2```
3mysql -u [username] -p;
4```
5
6Exit
7```
8exit;
9```
10
11Show all available databases in the MySQL database server
12```
13show databases;
14```
15
16Create a database
17```
18CREATE DATABASE database_name;
19```
20
21Use database or change current database to another database you are working with
22```
23USE database_name;
24```
25
26Drop a database with specified name permanently.
27```
28DROP DATABASE database_name;
29```
30
31Lists all tables in a current database.
32```
33show tables;
34```
35
36Create a new table or a temporary table
37```
38CREATE [TEMPORARY] TABLE [IF NOT EXISTS] table(
39 key type(size) NOT NULL PRIMARY KEY AUTO_INCREMENT,
40 c1 type(size) NOT NULL,
41 c2 type(size) NULL,
42 ...
43);
44```
45
46Query all data from a table
47```
48SELECT * FROM table
49```
50
51Query specified data which is shown in the column list from a table
52```
53SELECT column, column2….
54FROM table;
55```
56
57Query unique records
58```
59SELECT DISTINCT (column)
60FROM table;
61```
62
63Query data with a filter using a WHERE clause.
64```
65SELECT *
66FROM table
67WHERE condition;
68```
69
70Search for data using LIKE operator:
71```
72SELECT * FROM table
73WHERE column LIKE '%value%'
74```
75
76Text search using a regular expression with RLIKE operator.
77```
78SELECT * FROM table
79WHERE column RLIKE 'regular_expression'
80```
81
82Export data using mysqldump tool
83```
84mysqldump -u [username] -p [database] > data_backup.sql;
85```