

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a user exists in MySQL and drop it?
To check how many users are present in MySQL, use MySQL.user table. The syntax is as follows to check how many users are present.
mysql> SELECT User FROM mysql.user;
The following output displays the users −
+------------------+ | User | +------------------+ | Mac | | Manish | | mysql.infoschema | | mysql.session | | mysql.sys | | root | | Smith | | am | +------------------+ 8 rows in set (0.00 sec)
Now you can check and drop the user if it exist.
The syntax is as follows to drop a user from MySQL −
DROP USER IF EXISTS yourUserName;
Now you can implement the above syntax in order to drop if the user exists. I am applying drop on user ‘Mac’. The query is as follows.
mysql> DROP USER IF EXISTS Mac; Query OK, 0 rows affected (0.11 sec)
Check whether the user ‘Mac’ has been deleted or not. The query is as follows −
mysql> SELECT User FROM mysql.user;
The following is the output that displays user ‘Mac’ successfully deleted −
+------------------+ | User | +------------------+ | Manish | | mysql.infoschema | | mysql.session | | mysql.sys | | root | | Smith | | am | +------------------+ 7 rows in set (0.00 sec)
- Related Questions & Answers
- Check if table exists in MySQL and display the warning if it exists?
- Drop trigger if exists in MySQL?
- MySQL appears to DROP USER but user still exists in MySQL.users table?
- Check if MySQL entry exists and if it does, how to overwrite other columns?
- How to check if a table exists in MySQL and create if it does not already exist?
- How to check if a MySQL database exists?
- How to check if a python module exists without importing it?
- Check if a value exists in a column in a MySQL table?
- Check if a file exists in Java
- Check if a File exists in C#
- Check if value exists in a comma separated list in MySQL?
- MySQL create user if it does not exist?
- Check if MongoDB database exists?
- Check if a PHP cookie exists and if not set its value
- Check if a table is empty or not in MySQL using EXISTS
Advertisements