How can I check if a user exists?
Im doing an installer for a mysql database, and I need to check if a user exits, if not create user, if yes delete user and create it again.
this so i can execute the script without worries.
thanks.
Use the following query to show MySQL users created in the database server: SELECT user FROM mysql. user; As a result, you will see the list of all the users that have been created in MySQL.
$query = mysql_query("SELECT username FROM Users WHERE username=$username", $con); if (mysql_num_rows($query) != 0) { echo "Username already exists"; } else { ... }
User@% would allow access from all locations. User@localhost would only allow access from localhost. They are two different users with two different passwords (though you can set them to the same password, but if you update one password the other will not auto-update)
MySQL stores user data in a table called user
in a database named mysql
(by default). The following query will return 1
if a user with the specified username exists, 0
otherwise.
SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'username')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With