- for server
sudo apt install mysql-server
- for client
sudo apt install mysql-client
mysql -u USER -p -h HOSTNAME
SHOW DATABASES;
CREATE DATABASE db_name;
CREATE USER db_user@localhost;
SET PASSWORD FOR db_user@localhost= PASSWORD("password_of_username");
GRANT ALL PRIVILEGES ON db_name.* TO db_user@localhost IDENTIFIED BY 'password_of_username';
grant all privileges on `namespace\_%`.* to 'db_user'@'localhost' ;
DROP DATABASE db_name
mysqldump -u DB_USER -p DB_NAME > filename.sql
mysql -u root -p -h localhost DB_NAME < filename.sql
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] table(
key type(size) NOT NULL PRIMARY KEY AUTO_INCREMENT,
c1 type(size) NOT NULL,
c2 type(size) NULL,
...
);
ALTER TABLE table ADD [COLUMN];
ALTER TABLE table DROP [COLUMN];
ALTER TABLE table ADD INDEX [name](column, ...);
ALTER TABLE table ADD PRIMARY KEY (column,...)
ALTER TABLE table DROP PRIMARY KEY
DROP TABLE [IF EXISTS] table [, name2, ...] [RESTRICT | CASCADE]
CREATE [UNIQUE|FULLTEXT] INDEX index_name ON table (column,...)
DROP INDEX index_name
SELECT * FROM table
SELECT column, column2 FROM table;
SELECT DISTINCT (column) FROM table;
SELECT * FROM table WHERE condition;