Categories: Snippets

MySql Login, Database & User Creation

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

mysql -u [user] -p

Enter password:- Enter your mysql password

Step 2: Create the Database

mysql> create database [database_name];

Step 3: Verify that it’s there

mysql> show databases;

Step 4: Create the User

mysql> CREATE USER [new_user]@[hostname] IDENTIFIED BY [password];

Example:- CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'password123';

Step 5: Grant privileges while assigning the password

mysql> GRANT ALL PRIVILEGES ON [database] . * TO [new_user]@[hostname];

Example:- GRANT ALL PRIVILEGES ON databasename . * TO 'dbuser'@'localhost';

*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 selectinsert, and delete.
Choose all that apply and separate by comma:

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

 

Share

Recent Posts

Generate Slug URL in MySQL

A slug is a short name using human-readable keywords to identify a web page. For…

5 years ago

How to use SQL LIKE condition with multiple values in PostgreSQL?

[crayon-662d45dc89239137482383/]  

5 years ago

SELECT Null

[crayon-662d45dc89327901533115/]  

5 years ago

ALTER Column SET NOT NULL – pgSQL

[crayon-662d45dc89409327166701/]  

5 years ago

ADD new Column – pgSQL

[crayon-662d45dc89543573954767/] [crayon-662d45dc89549370905652/]  

5 years ago