Step 1: Login to MySQL ( you will need an account )
1 |
mysql -u [user] -p |
Enter password:- Enter your mysql password
Step 2: Create the Database
1 |
mysql> create database [database_name]; |
Step 3: Verify that it’s there
1 |
mysql> show databases; |
Step 4: Create the User
1 |
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
1 |
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 select, insert, and delete.
Choose all that apply and separate by comma:
1 |
grant select, insert, delete, update on db_name.* to 'db_user'@'localhost' identified by 'db_password'; |