Tuesday, July 15, 2008

Adding New User to MySQL

I had a tough time getting this to work, so I'm putting it here. To add a new user to a MySQL database:

CREATE USER 'username'

then:

GRANT SELECT, INSERT
ON 'database'.*
TO 'username'
IDENTIFIED BY 'password'

This creates a user named username and gives them Select and Insert privileges to the database called database. They will need to log in with the password password.

To log in to MySQL as this user:

mysql -u username -p

This will prompt them for their password as assigned above.

No comments: