MySQL Create Database and Add User

Here’s a quick overview of the commands involved in creating a MySQL database, creating a user and adding them to the database and importing an sql backup into the newly created database.

*This assumes you already have some way to log in to the database with a privileged account.

Log in to MySQL an existing user

$ mysql -u myuser -p 

Create the database

$> create database my_database_name;

Create the user and grant privileges on all databases

$> create user 'smith'@'localhost' identified by 'secret_password';
$> grant all privileges on *.* to 'smith'@'localhost' with grant option;

Import a backed up sql file


$ mysql -u smith -p my_database_name < my_db_backup.sql

Reference:
http://dev.mysql.com/doc/refman/5.1/en/adding-users.html

Leave a Reply

Your email address will not be published. Required fields are marked *