We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,645 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Check if user exists

I need to check if a databse user exists and if not, create that user.

However, I do not know the statement to check if a user already exits.

How to check if a user already exists in MySQL?

4
Contributors
5
Replies
3 Years
Discussion Span
1 Year Ago
Last Updated
7
Views
Question
Answered
tuse
Junior Poster
174 posts since Jul 2007
Reputation Points: 32
Solved Threads: 14
Skill Endorsements: 0
select user from mysql.user where user='  ';

you should have access to mysql DB to execute the query

varmadba
Junior Poster in Training
83 posts since Jun 2008
Reputation Points: 22
Solved Threads: 9
Skill Endorsements: 0

Thanks a lot.

Didn't see the 'mysql' database.

tuse
Junior Poster
174 posts since Jul 2007
Reputation Points: 32
Solved Threads: 14
Skill Endorsements: 0

Hi tuse

How are you?

Thanks a lot.

Didn't see the 'mysql' database.

Well, if you had access to grant table mysql.user you would have also been able to
SELECT User, Password FROM mysql.user. You got it? Yes, you would be able to hack that
mysql database. So it's a good idea that not everybody is allowed to "see" grant table.

Happy hacking !

krs,
tesu

tesuji
Master Poster
721 posts since Apr 2008
Reputation Points: 158
Solved Threads: 98
Skill Endorsements: 0

Hi tesu!

I have (somehow) managed to see the mysql database!

tuse
Junior Poster
174 posts since Jul 2007
Reputation Points: 32
Solved Threads: 14
Skill Endorsements: 0
Question Answered as of 4 Years Ago by tesuji and varmadba
mysqladmin -u 'user' -p 'password' status

this function returns 0 and a line if the user exists, !0 else.

Offirmo
Newbie Poster
1 post since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0714 seconds using 2.68MB