Thanks for coming to this particular blog among many mysql commands cheatsheet. I am gathering all the mysql commands that I go through and update them here.
Create User and Grant Privileges
1
2
3
4
5
CREATE USER 'flaskuser'@'localhost' IDENTIFIED BY 'flaskpassword';
GRANT ALL PRIVILEGES ON flaskdb.* TO 'flaskuser'@'localhost';
FLUSH PRIVILEGES;
Mysql Dumps
1
2
3
4
5
6
7
# Export Database
$ mysqldump -u[mysql_user] -p [db_name] > `date +%Y-%m-%d-%H:%M:%S`.sql
# Import Database
$ mysql -uroot -p [db_name] < 2018-09-01.sql
Create Database :
1
CREATE DATABASE my_database;
Create Table :
1
2
3
4
5
6
CREATE TABLE my_table (
id int primary key auto_increment,
Name varchar(50),
Address varchar(40),
Gender enum ("Male", "Female")
)
Alter Table :
1
ALTER TABLE my_table RENAME my_tbl;
Deleting Table :
1
DROP TABLE my_tbl;
Renaming Column Name :
1
2
ALTER TABLE my_tbl
CHANGE full_name name varchar(50);
Delete Column
1
ALTER TABLE my_tbl drop name;
Adding Column
1
ALTER TABLE my_tbl ADD roll int;
Basic CRUD commands
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-- Insert
INSERT INTO my_tbl
(id,name,address,gender)
values (‘1’,’sisir’,’ktm’,’male’);
-- Update
UPDATE my_tbl
set name = ‘ccr’ where id=‘1’;
-- Select
SELECT * FROM my_tbl where id=‘2’;
-- Delete
DELETE from my_tbl where id = ‘2';