Skip to content

Instantly share code, notes, and snippets.

@cuibonobo
Last active September 6, 2016 11:38
Show Gist options
  • Save cuibonobo/022ca939e5e080b7f585d9d45cde3e61 to your computer and use it in GitHub Desktop.
Save cuibonobo/022ca939e5e080b7f585d9d45cde3e61 to your computer and use it in GitHub Desktop.
Creating a new user in MySQL and granting it privileges to a database.

Source: https://geekpeek.net/create-mysql-database/

mysql -u root -p

You should now be inside the MySQL repl. Do the following:

CREATE DATABASE `firstdb` /*!40100 DEFAULT CHARACTER SET utf8 */;
CREATE USER 'firstuser'@'localhost' IDENTIFIED BY 'HardPass';
GRANT ALL PRIVILEGES ON firstdb.* TO 'firstuser'@'localhost';
FLUSH PRIVILEGES;

Quit the MySQL repl by typing quit.

You can test the permissions by starting the MySQL repl as the user you just created and entering show databases;

Run a SQL script on a database with:

mysql -u firstuser -p firstdb < dbdump.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment