Created by CyanHall.com on 11/13/2020 , Last updated: 04/01/2021.
πŸ‘‰Β Β github shields Star me if it’s helpful.

1. CLI Login

    mysql -h localhost -u root -p
// /usr/local/Cellar/[email protected]/x.xx.xx/bin/mysql -h localhost -u root
  

2. import an SQL file

    mysql -u username -p database_name < file.sql
  

3. List all databases

    show databases;
  

4. List all tables in a database

    use [db name];
show tables;
  

5. List all users

    SELECT User, Host, authentication_string FROM mysql.user;
  

6. Create user and database

    # Create a user
CREATE USER 'db_user'@'localhost' IDENTIFIED BY 'password';

# Create a database
CREATE DATABASE example_db;

# Grant privileges
GRANT ALL ON example_db.* TO 'db_user'@'localhost';
  

7. Delete user and database

    # Delete database
DROP DATABASE example_db;

# Delete user
DROP USER 'db_user'@'localhost';
  

8. Quit CLI

    quit
  

1. CLI Login

    mysql -h localhost -u root -p
// /usr/local/Cellar/[email protected]/x.xx.xx/bin/mysql -h localhost -u root
  

3. List all databases

    show databases;
  

5. List all users

    SELECT User, Host, authentication_string FROM mysql.user;
  

7. Delete user and database

    # Delete database
DROP DATABASE example_db;

# Delete user
DROP USER 'db_user'@'localhost';
  

2. import an SQL file

    mysql -u username -p database_name < file.sql
  

4. List all tables in a database

    use [db name];
show tables;
  

6. Create user and database

    # Create a user
CREATE USER 'db_user'@'localhost' IDENTIFIED BY 'password';

# Create a database
CREATE DATABASE example_db;

# Grant privileges
GRANT ALL ON example_db.* TO 'db_user'@'localhost';
  

8. Quit CLI

    quit
  


Maitained byΒ Cyanhall.com, Copy Rights @ CC BY-NC-SA 4.0