Mysql ERROR 1396 (HY000) 错误的解决办法

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群版 2核4GB 100GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用版 2核4GB 50GB
简介:

建立用户的时候报告这个错误:

ERROR 1396 (HY000): Operation CREATE USER failed for 'abc'@'localhost'

原因是mysql中已经有了这个用户,从mysql.user中直接删除delete,然后刷新权限FLUSH PRIVILEGES,再建用户就不会有这个问题了。

如果是drop user 的话,mysql内部会自动刷新一下,那么再建也不会有这问题了。


举例说明1——delete删除:

mysql> create user 'abc'@'localhost';

Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from user;

+------+-----------+

| user | host |

+------+-----------+

| root | 127.0.0.1 |

| abc | localhost |

| root | localhost |

+------+-----------+

3 rows in set (0.00 sec)


mysql> delete from user where user='abc';

Query OK, 1 row affected (0.00 sec)

mysql> select user,host from user;

+------+-----------+

| user | host |

+------+-----------+

| root | 127.0.0.1 |

| root | localhost |

+------+-----------+

2 rows in set (0.00 sec)


再次创建同名用户,报错如下:

mysql> create user 'abc'@'localhost';

ERROR 1396 (HY000): Operation CREATE USER failed for 'abc'@'localhost'

这里要刷新权限,刷新之后就可以创建了;

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)


mysql> create user 'abc'@'localhost';

Query OK, 0 rows affected (0.00 sec)


mysql> select user,host from user;

+------+-----------+

| user | host |

+------+-----------+

| root | 127.0.0.1 |

| abc | localhost |

| root | localhost |

+------+-----------+

3 rows in set (0.00 sec)



举例说明2——drop 删除,可以直接创建:

mysql> drop user 'abc'@'localhost';

Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from user;

+------+-----------+

| user | host |

+------+-----------+

| root | 127.0.0.1 |

| root | localhost |

+------+-----------+

2 rows in set (0.00 sec)


mysql> create user 'abc'@'loaclhost';

Query OK, 0 rows affected (0.00 sec)





本文转自 模范生 51CTO博客,原文链接:http://blog.51cto.com/mofansheng/1980514,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
2月前
|
关系型数据库 MySQL
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file
77 0
|
6天前
|
关系型数据库 MySQL
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file
13 2
|
2月前
|
关系型数据库 MySQL 数据库连接
解决 mysql8.0 ERROR 1045 (28000): Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)用户访问拒绝
解决 mysql8.0 ERROR 1045 (28000): Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)用户访问拒绝
443 52
解决 mysql8.0 ERROR 1045 (28000): Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)用户访问拒绝
|
17天前
|
网络协议 关系型数据库 MySQL
启动mysql时的异常为:[ERROR] Can‘t start server: Bind on TCP/IP port. Got error: 98: Address already in used
启动mysql时的异常为:[ERROR] Can‘t start server: Bind on TCP/IP port. Got error: 98: Address already in used
|
15天前
|
SQL 关系型数据库 MySQL
You have an error in your SQL syntax;check the manual that corresponds to you Mysql server version
You have an error in your SQL syntax;check the manual that corresponds to you Mysql server version
|
17天前
|
关系型数据库 MySQL 数据库
mysql 中登录报错:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)ERROR
mysql 中登录报错:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)ERROR
|
22天前
|
SQL 存储 关系型数据库
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
|
23天前
|
SQL 关系型数据库 MySQL
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
|
2月前
|
关系型数据库 MySQL 数据库
MySQL 启动 登录报错Job for mysqld.service failed because the control process exited with error code. See
MySQL 启动 登录报错Job for mysqld.service failed because the control process exited with error code. See
|
2月前
|
关系型数据库 MySQL Linux
【Linux】安装Mysql(附加service mysql启动失败 提示unit not found 解决办法)
【Linux】安装Mysql(附加service mysql启动失败 提示unit not found 解决办法)
181 0

推荐镜像

更多