Skip to content

Instantly share code, notes, and snippets.

@samatsav
Created September 24, 2013 14:49
Show Gist options
  • Save samatsav/6685892 to your computer and use it in GitHub Desktop.
Save samatsav/6685892 to your computer and use it in GitHub Desktop.
Add a new user to a MySQL database from the command line
mysql -u root -p
/* Then enter your password and hit enter. Now we want to create a database which our new user will have privileges on. If you already have a database you can skip this step. */;
mysql > create database new_database;
/* Now with our new database in place called new_database we can move on and set up a user for this schema. */;
mysql > grant usage on *.* to new_database_user@localhost identified by 'user_password';
/* Now we want the new user to be able to do almost everything in the new database so we run: */;
mysql > grant all privileges on new_database.* to new_database_user@localhost;
/* Now to make sure all the settings we entered stick we run: */;
mysql > flush privileges;
/* Now you should be able to easily log in to the database called new_database on the localhost. If you wanted the user to be able to access the database from any location than you would run the following line instead of the one above: */;
mysql > grant usage on *.* to new_database_user@'%' identified by 'user_password';
/* Hope this helps people remember how to add users really is in MySQL on the command line. */;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment