

+-+-+-+-+-+-+-+-+ Code language: PHP ( php )Īs you see, the user account has the connection id id 21. | 21 | alice | localhost: 64060 | people | Sleep | 14 | | NULL | | 20 | root | localhost: 63851 | NULL | Query | 0 | starting | show processlist | | 4 | event_scheduler | localhost | NULL | Daemon | 31803 | Waiting on empty queue | NULL | | Id | User | Host | db | Command | Time | State | Info | If you cannot do so, you can kill user sessions first before dropping the user account.Įighth, use the SHOW PROCESSLIST statement from the root’s session to find the id of the connection: +-+-+-+-+-+-+-+-+ In this case, you should inform the user first. If you drop a currently connected user, the user can operate as normal until the next login. Suppose that you want to drop the user the user account is still connected to MySQL Server. Seventh, insert a row into the persons table: mysql> insert into persons(firstname, lastname) values( 'John', 'Doe') Code language: SQL (Structured Query Language) ( sql ) Sixth, select the people database: mysql> use people Code language: SQL (Structured Query Language) ( sql )
Mysql delete user force password#
Type the password for the user account alice and press the Enter key: Enter password: ************ Code language: SQL (Structured Query Language) ( sql ) > primary key( id)) Code language: SQL (Structured Query Language) ( sql )įourth, grant all privileges on the people database to the account user alice: mysql> grant all privileges on people.* to Code language: SQL (Structured Query Language) ( sql )įifth, launch another session and connect to the database using the user mysql -u alice -p Code language: SQL (Structured Query Language) ( sql )


Third, create a new table persons in the people database: mysql> create table persons( Second, select the people database: mysql> use people Code language: SQL (Structured Query Language) ( sql )

Here is the output: + -+-+Ħ rows in set ( 0.00 sec) Code language: SQL (Structured Query Language) ( sql ) C) Using MySQL DROP USER to drop a connected userįirst, create a new database called people: mysql> create database people Code language: SQL (Structured Query Language) ( sql ) Second, show users from the current database: mysql> select user, host from er B) Using MySQL DROP USER to drop multiple user accounts at onceįirst, remove two user accounts remote using the following statement: mysql> drop user remote The user account been removed successfully. Here is the current user list: + -+-+ĩ rows in set ( 0.00 sec) Code language: SQL (Structured Query Language) ( sql )įourth, drop the user by using the DROP USER statement: mysql> drop user Code language: SQL (Structured Query Language) ( sql )įifth, show all users again: mysql> select user, host from er Ĭode language: SQL (Structured Query Language) ( sql ) + -+-+Ĩ rows in set ( 0.00 sec) Code language: SQL (Structured Query Language) ( sql ) Third, show users from the MySQL Server: mysql> select user, host from er Code language: SQL (Structured Query Language) ( sql ) Second, create four account users accounts remote, and mysql> create user remote, identified by 'Secure1Pass!' Code language: SQL (Structured Query Language) ( sql ) Type the password for the root user and press Enter: Enter password: ******** Code language: SQL (Structured Query Language) ( sql ) A) Using MySQL DROP USER statement to drop a user exampleįirst, connect to the MySQL Server using the root account: mysql -u root -p Code language: SQL (Structured Query Language) ( sql ) Let’s take some examples of dropping users. Ĭode language: SQL (Structured Query Language) ( sql )īesides removing the user account, the DROP USER statement also removes all privileges of the user from all grant tables. In MySQL 5.7.8+, you can use the IF EXISTS clause to conditionally drop a user only if it exists: DROP USER account_name. If you remove a user account that doesn’t exist, MySQL will issue an error. Code language: SQL (Structured Query Language) ( sql ) If you want to remove multiple user accounts at once, you specify a list of comma-separated user accounts in the DROP USER clause: DROP USER account_name. In this syntax, you specify the name of the user account that you want to remove after the DROP USER keywords.
