2

这就是我所做的。

mysql> CREATE USER 'matrix'@'%.something.com' IDENTIFIED BY 'weak';
ERROR 1396 (HY000): Operation CREATE USER failed for 'matrix'@'%.something.com'
mysql> CREATE USER 'foo'@'%.something.com' IDENTIFIED BY 'weak';
Query OK, 0 rows affected (0.00 sec)

这就是我最终的结果:

mysql> select user,host from mysql.user;
+------------------+--------------------+
| user             | host               |
+------------------+--------------------+
| auth             | %.something.com    |
| foo              | %.something.com    |
| submit           | %.something.com    |
| testcase         | %.something.com    |
| version          | %.something.com    |
| root             | 127.0.0.1          |
| root             | this.something.com |
| debian-sys-maint | localhost          |
| master           | localhost          |
| root             | localhost          |
+------------------+--------------------+
10 rows in set (0.00 sec)

似乎问题在于我通过 a 删除了用户DELETE FROM mysql.user WHERE User IN (%s);以解决我不知道帐户是否存在的问题。

我的(丑陋的)解决方案,替换为DELETE FROM mysql.user WHERE...

DELIMITER //
CREATE PROCEDURE dropuserif(u VARCHAR(32), h VARCHAR(64))
BEGIN
  DECLARE s INT;
  SELECT COUNT(*) INTO s FROM mysql.user WHERE user = u AND host = h;
  IF s > 0 THEN
    BEGIN
      SET @d = CONCAT("DROP USER '", u, "'@'", h, "';");
      PREPARE stmt_name FROM @d;
      EXECUTE stmt_name;
      DEALLOCATE PREPARE stmt_name;
    END;
  END IF;
END//
DELIMITER ;
4

2 回答 2

2

在网络上搜索“错误 1396”会出现此错误报告

原因似乎是以前删除的用户条目仍然以某种方式潜伏在数据库中,并阻止创建具有相同名称的新帐户。

FLUSH PRIVILEGES;在第一个语句之前尝试 a并再次运行它们。

于 2010-09-10T14:49:07.193 回答
0

在这里寻找解决此问题的良好开端

[snark] 你不只是搜索' mysql ERROR 1396'有什么原因吗?[/snark]'

于 2010-09-10T14:53:01.323 回答