
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- 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?
- How to check if a user email already exists in Laravel?
- 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?
- Check if a value exists in a column in a MySQL table?
- Check if value exists in a comma separated list in MySQL?
- How to check if a python module exists without importing it?
- Check that a table exists in MySQL?
- Check if a table is empty or not in MySQL using EXISTS
- Check if a File exists in C#
- MySQL create user if it does not exist?
- How to check if a specific country code exists in a cell with MySQL?

Advertisements