Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between DROP USER and deleting a row from the mysql.user table

I have a database with hundreds of active connections at any point in time. When I use the DROP USER sql statement to remove a user account, it takes ~4 seconds, during which all other connections have the state "Checking permissions". This means that to delete 1000 users, I'll effectively be locking the database for a good part of 4000 seconds, which is unacceptable. I do notice, however, that deleting a user row from the mysql.users table is instant.

Is deleting a row from mysql.users kosher? What are the drawbacks compared to using DROP USER? Am I leaving stale rows elsewhere? Are there propagation issues? I'm most likely going to have to go this route, but I want to know what other clean up I'll need to do.

like image 376
BrainCore Avatar asked May 12 '12 01:05

BrainCore


People also ask

How do I delete a row from a table in MySQL?

To delete rows in a MySQL table, use the DELETE FROM statement: DELETE FROM products WHERE product_id=1; The WHERE clause is optional, but you'll usually want it, unless you really want to delete every row from the table.

How do I drop a user in MySQL?

To use DROP USER , you must have the global CREATE USER privilege, or the DELETE privilege for the mysql system database. When the read_only system variable is enabled, DROP USER additionally requires the SUPER privilege. Each account name uses the format described in Section 6.2. 4, “Specifying Account Names”.

Which query is used to remove user?

The DROP USER statement is used to remove a user from the SQL Server database.


1 Answers

Depends on your version of MySQL

Drop user in MySQL <= v5.0 only removed the user record but not privileges. MySQL >= v5.0.2 does both in a single go.

Also multiple users can be passed.

like image 145
codemonkee Avatar answered Sep 30 '22 15:09

codemonkee