Monday, December 22, 2008

MySQL: Creating a database and User account

For my next installment, I will show you how to not only create a database (which isn't that trivial), but also how to create a user to access that database and assign their password all at once.

First, the database. So, what we will do here is first, log in as root user:

mysql -u root -p

Hit enter and type in the root password when prompted. There are other ways of doing this, like the following, its just how I chose to do it:

mysql -uroot -p<password>

Just replace <password> with the root user password. Then, at the mysql prompt, create the desired database (that we will call testing for our purposes here):

create database testing;

Now, you will want to access this database with a specific user account (which we will call tester) and give it a password. So, at the mysql prompt do the following:

grant all on testing.* to 'tester'@'localhost' identified by 'password';

This assumes that you are working on the machine where the database is located. Also, replace 'password' with the password you wish to use.

That's it. You should now be able to exit out of mysql and then log in using the new account you have just created. (provided you didn't receive any errors during the above statements.

No comments:

 
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.