How to Create MySQL Database, User, Password and grant permission.

MySQL-  MySQL is an open-source database management system, commonly installed as part of the popular LAMP(Linux, Apache, MySQL, PHP/Python/Perl) stack. It uses a relational database and SQL (Structured Query Language) to manage its data.



Prerequisites- 

  • Linux Machine or Windows machine with Install MySQL server.
  • MySQL access with super privileges.
Before, We start Creating MySQL database, User, Password and grant user permission on a specific database. Make sure you have a Linux box with installed MySQL server. For those, who want to install MySQL server on Ubuntu 16.04, Follow this blog- How to Install MySQL
Step 1- Access MySQL Shell:
Log on to MySQL shell with the user have super privilege and run the following command to create a new database. Windows user can open MySQL shell by searching "MySQL Client" on the Windows search.
Access MySQL shell: To access MySQL shell from the local server using this command. If you are trying to access MySQL server from the remote machine then please use hostname also.
1 A- Access MySQL Shell local server
$ mysql -u root -p
1 B- Access MySQL shell from Remote machine.
$ mysql -u root -p -h 192.168.102.10

Step 2- Create a database- To create a new database, Use the following command.
mysql> create database Linux;
Where:
Create database =     is a command.
Linux                 =     is database name.
Step 3- Create a User: To create a new user, Use the following command.
mysql> create user amar@'localhost' identified by 'mypassword';
Step 4- Grant Permission- To grant user permission on a database follow the command below.
4A- Grant Database access from localhost only-
mysql> grant all privileges on Linux.* To amar@'localhost' identified by 'mypassword'; 

4B- To Grant Database access from the remote host.
mysql> grant all privileges on Linux.* To amar@'192.168.102.12' identified by 'mypassword'; 
Step 5- Reload privileges- To reload user privileges use the following command.

mysql> FLUSH PRIVILEGES;
Step 6- List database, user and host- To get the list of database, User and host use the below command.
mysql> select db,host,user from mysql.db;
Step 7- Drop database-
To drop database use the following command.
mysql> drop database database_Name;
Step 8- Drop User-
To drop User follow the below command. If you want to delete a user with localhost then it should be "@localhost" for Remote host address use "@remotehost_IP"
mysql> drop user User_Name@'Host_Name';
To Remove user with localhost
To Remove user With remote host address

!!Cheers!!

No comments:

Post a Comment