0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MySQLで ERROR 1064 (42000) のエラーが出てユーザーが削除できないときの対処法

Last updated at Posted at 2023-03-05

MySQLでユーザーを削除しようとしたところ 「ERROR 1064 (42000)」が出ました。
原因は、ユーザー名にハイフンがあったからです。
シングルクォーテーションでユーザー名を囲むと削除できます。
これはデータベースなどを削除するときも同じようです。
(こちらの記事では「バッククォートで囲む」とありますが、シングルクォーテーションでもできました)

mysql> SELECT user, host FROM mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| dev-user         | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
5 rows in set (0.03 sec)

mysql> DROP USER dev-user;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-user' at line 1
mysql> DROP USER 'dev-user';
Query OK, 0 rows affected (0.08 sec)

mysql> 
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?