Features
How to add a new user to MySQL server

Copyright © TechPad.co.uk
The command line fu you need to know in order to add a new user to your MySQL server.
Step 1: Add the userLogin to MySQL with the root user password by entering into your terminal mysql -u root -p, then entering your MySQL root password. To create a new user account enter the following:
CREATE USER 'matt'@'localhost' IDENTIFIED BY 'c0MpLiCaTeDp@55w0rd';
To confirm that it works, quit out of MySQL and enter mysql -u matt -p to try and login with the account you've just created. You should see the MySQL prompt if it's been successful.
Step 2: Give the user privileges
I want my account, on a development machine, to have access to everything on all databases.
However, this is not very secure and if you're adding a user account to a proper system you'll want to restrict what databases users can connect to and what the users can do.
If someone manages to execute a command using the user account via, for example, a SQL Injection vulnerability in a web application, you don't want them to be able to drop databases on your server, so you should restrict what the web user can do.
To give our user limited access to the important and widely used commands, SELECT, INSERT, UPDATE and DELETE you can issue the following command, which gives database-wide access to only these commands:
GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'matt'@'localhost';
If you want to give root-like privileges, on a local development machine, you can create a user with these privileges using the command:
GRANT ALL ON *.* TO 'matt'@'localhost';
Published: TechPad.co.uk Monday 28 December 2009, 6:31 pm
Views: 17,330 times
Filed under: MySQL server Linux Ubuntu
Login to leave your comments
Please login









Recent comments
iplayer-dl is a Ruby application, which will run most easily on Linux or Mac (hence the Mac scree...
TechPad: 18:18 PM Aug 22nd, 2010
I don't understand how to use this. I have vista and firefox. Do I need to copy the iplayer int...
mufc1977: 15:15 PM Aug 21st, 2010
No worries, glad you got the buttons back in their rightful place!
TechPad: 13:13 PM Aug 12th, 2010
Disregard my previous comment: The FIRST time I tried it, it definitely didn't work. After addi...
freshrich: 1:01 AM Aug 10th, 2010
Great tutorial, but it doesn't work with Ubuntu Lucid. The only way I could get it to work was b...
freshrich: 1:01 AM Aug 10th, 2010