MySQL Basic Commands

How to login into MYSQL through terminal

sudo mysql -h hostname -u username -p

Create a database
List all databases

 mysql> create database databasename;

mysql> show databases;

List all tables of test database
To delete a database or a table

mysql> use test;

mysql> show tables;

mysql> drop database databasename;

mysql> drop table tablename;

List all Users of MySQL
List only Host, User and Password of MySQL

mysql> select * from mysql.user;

mysql> select host, user, password from mysql.user;

Create a user in mysql

mysql> CREATE USER ‘newuser’@’localhost’ IDENTIFIED BY ‘user_password’;

Grand all privileges to a user account over a specific database

mysql> GRANT ALL ON dbname.* TO ‘username’@’localhost’ IDENTIFIED BY ‘password’ ;

Change password of mysql user

mysql>  ALTER USER  ‘username@localhost’ IDENTIFIED BY ‘new password’;

Take a backup of MySQL database

shell>  mysqldump -u username -p –database databasename > databasename.sql

Restore mysql backup

mysql> source /path_of_file/filename.sql;

Working on more commands!

100% LikesVS
0% Dislikes

One Comments

  • Very energetic article, I liked that a lot.
    Will there be a part 2?

Comments are closed.