Membership Membership:
Latest New User Latest: vpros
Past 24 Hours Past 24 Hours: 0
Prev. 24 Hours Prev. 24 Hours: 0
User Count Overall: 137

People Online People Online:
Visitors Visitors: 84
Members Members: 0
Total Total: 84

NakedMCSE Computer Tech Support Forums

So you have passed all of the exams and you are now out in the real world of windows servers, linux servers and freebsd servers faced with a tech support problem you have never seen before...

Find free online tech support in the forums below, respecting that advice is free, but work beyond advice is not...

The General forum is provided for off topic discussion.

You need a user account to post - please Register or Login.

Online Tech Support Forums
 
  Forum  Open Source Tec...  MySQL Server  Create User in MySQL
Previous Previous
 
Next Next
New Post 12/16/2009 3:49 PM
Informative
  Walker
119 posts
www.lairdscomputer.com
10th Level Poster


Create User in MySQL 

One of the most basic MySQL admin tasks is creating users and assigning them rights to databases.

Users can be created with the 'create user' command:

create user 'myuser'@'localhost' identified by 'mypass';
create user 'myuser'@'host.mysite.com' identified by 'mypass';
create user 'myuser'@'%' identifed by 'mypass';

In these you replace 'myuser' and 'mypass' with appropriare values.  The first form creates a local only user, the second form (with the @'%') creates a user who can login from anywhere and the third form creates a user who can login from a specific host (you replace 'host.mysite.com' with the correct address).

Once the user is created, you need to assign (grant) rights to databases.  This is done through the grant command:

grant all privileges on mydb.* to 'myuser'@'localhost' with grant option;
grant select,insert,update,delete on mydb.* to 'myuser'@'%';
grant select on mydb.* to 'myuser'@'host.mysite.com';

The first form grants all rights on the mydb database to the myuser user on the local machine.  It also allows myuser to grant rights to the database ('with grant option').  The second form grants a more reduced set of rights - select, insert, update and delete only on mydb database to the myuser user from any machine.  The final form grants just the select right on the mydb database to the myuser user from the host 'host.mysite.com'.

Once you have granted rights you need to flush them in order for them to take effect.  You can do this using the flush command:

flush privileges;

Walker
www.lairdscomputer.com

 
Previous Previous
 
Next Next
  Forum  Open Source Tec...  MySQL Server  Create User in MySQL
Send me One Million FREE Guaranteed Visitors