Create a MySQL Database, Username and Password from the command line



This is how to create a MySQL database, username and password from the command line:

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

user@yourhost ~ mysql -u mysql_user -p

2: Create Database

mysql > create database db_name;

3: Create User

mysql > create user db_user;

4: Grant privileges and assigning password

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

If you don't want to grants all privileges and you want to limit privileges to select, insert, and delete :

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

5: If you want to delete the user (in case you made a mistake)

GRANT USAGE ON *.* TO 'db_user'@'localhost';
DROP USER 'db_user'@'localhost';

And the database

DROP DATABASE db_name;



Any thoughts?

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

Loading more content...