3

How to drop 'user'@'%' on the MySQL CLI using the mysql -e command?

mysql -uroot  -p -e "'myuser'@'%'";

This does not work.

1

You have to surround the % character with single quotes

DROP USER user@'%';

or put the user in single quotes as well

DROP USER 'user'@'%';

From the CLI, you would run something like this

MYSQL_USER=root
MYSQL_PASS=rootpassword
MYSQL_CONN="-u${MYSQL_USER} -p${MYSQL_PASS}"
SQL="DROP USER 'user'@'%'"
mysql ${MYSQL_CONN} -ANe"${SQL}"

An alternative method would be delete it from mysql.user

MYSQL_USER=root
MYSQL_PASS=rootpassword
MYSQL_CONN="-u${MYSQL_USER} -p${MYSQL_PASS}"
SQL="DELETE FROM mysql.user"
SQL="${SQL} WHERE user='user'"
SQL="${SQL} AND host='%';"
SQL="${SQL} FLUSH PRIVILEGES;"
mysql ${MYSQL_CONN} -ANe"${SQL}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.