Home » Database » [Mysql Basic] Create Database Username Password Tables

[Mysql Basic] Create Database Username Password Tables

Basic Commands of Mysql to create a database, create a table, create a user with password and give privilages to the table. These commands can be used in a Mariadb terminal without modification. Because Mariadb is compatible with Mysql also.

Mysql command line is used for managing linux servers in remote hosting. These commands are usefull in managing databases in Linux VPS servers and local linux hosting servers without a graphical utility like phpMyAdmin or Chive.


Lets have a look at the basic commands here.


Step 1: Login to MySQL ( you will need an account )

[email protected]:~$ mysql -u mysql_user -p
Enter password:

the mysql_user is replaced with the real user name may be root or the username of the login

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.37-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]>

Step 2: Create a new Database in mysql server

mysql > create database database_name;

the database_name will be replaced with your database name like movies, accounts etc..

Step 3: View all existing databases in the mysql server

mysql > show databases;

Step 4: Create a new user in mysql database.

mysql > create user db_user;

Step 5: Grant privileges while assigning the password

mysql > grant all on db_name.* to 'db_user'@'localhost' identified by 'db_password';

*Note: The localhost field usually doesn’t have to be edited, but you can set it to the specific address.

The above example grants all privileges, obviously. But you will likely want to limit privileges under many circumstances. These parameters include select, insert, and delete.
Choose all that apply and separate by comma, thusly:

mysql > grant select, insert, delete on db_name.* to 'db_user'@'localhost' identified by 'db_password';

Step 6: Create a table in the database

mysql > use database_name;

To change to the current database where the table is created

Step 7: Create a table in the database

mysql > create table_name;

just create a table in the database.

Drop Database: Just delete a database from the current mysql server. Beware all data will be lost

mysql > drop database database_name;

These are the commands for mysql terminal. It usually work with mariadb terminal without any change. So you can use these commands in mariadb also without any modification


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.