Browse Articles in Web Development
Andre Honsberg Andre Honsberg is a software engineer who develops mostly for the Web. He lives in Hamburg Germany and works building software for the web using a wide spectrum of different technologies.

alt textIn this article we will go over how to add a new user to a MySQL database from the Linux command line. This method should work from any operating system that uses the MySQL client application from a terminal.

First we need to log into MySQL on a server so lets do that right now.

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.

Want to leave a Commnet?