Skip to content

Instantly share code, notes, and snippets.

@mahendra0859
Last active October 22, 2020 10:14
Show Gist options
  • Save mahendra0859/cceeec57b9f6e52d55a1e46d6a2bca37 to your computer and use it in GitHub Desktop.
Save mahendra0859/cceeec57b9f6e52d55a1e46d6a2bca37 to your computer and use it in GitHub Desktop.
MySQL Commands

Basic SQL commands

Click here to download MySQL Community Server - DB

Click here to download MySQL Workbench - UI

Click here to download MySQL Shell

AWS RDS MYSQL import db Access Denied

To create database

$ CREATE DATABASE test;
To drop database

$ DROP DATABASE test;
To create database

$ CREATE DATABASE record_company;
Selecting database o make CRUD queries run

$ USE record_company;
To create table in database

$ CREATE TABLE test(
test_column INT
);
To modify the table in database

$ ALTER TABLE test
ADD another_column VARCHAR(255);
To delete/drop the table in database

$ DROP TABLE test;
To create table with primary key in database

$ CREATE TABLE bands (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
PRIMARY KEY(id)
);
To create table with foriegn key in database

$ CREATE TABLE albums (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
release_year INT,
band_id INT NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(band_id) REFERENCES bands(id)
);
To add rows to the table

$ INSERT INTO bands (name)
VALUES ('Iron Maiden');
To add multiple rows to the table

$ INSERT INTO bands (name)
VALUES ('Deuce'), ('Avenged Sevenfold'), ('Ankor');
Fetching all the data from table

$ SELECT * FROM bands;
Fetching all the data which has only distinct (different) values from table

$ SELECT DISTINCT column1 FROM bands;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment