Mysql 5.5 源码安装后创建用户报错"ERROR 1045 (28000): Access denied for user"
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,安装MySQL后,root用户可设置密码登录,其他新建的用户不能通过密码登录,只能不输入密码登录,而且对新建用户的授权均无效。--创建一个库和用户 mysql> create database fir
千家信息网最后更新 2026年11月01日Mysql 5.5 源码安装后创建用户报错"ERROR 1045 (28000): Access denied for user"安装MySQL后,root用户可设置密码登录,其他新建的用户不能通过密码登录,只能不输入密码登录,而且对新建用户的授权均无效。
mysql> create user neo identified by 'Mysql#2015'; Query OK, 0 rows affected (0.00 sec)
mysql> grant select,create,update,delete on fire.* to neo; Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
--使用新用户登录报错
[root@localhost data]# ./bin/mysql -u neo -p"Mysql#2015"
ERROR 1045 (28000): Access denied for user 'neo'@'localhost' (using password: YES)
--但是不输入密码却可以登录
[root@localhost software]# ./bin/mysql -uneo
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.5.48-log production environment
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show grants;
+--------------------------------------+
| Grants for @localhost |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+
1 row in set (0.00 sec)
报错原因:Mysql使用源码安装后,数据库中存在匿名用户,可以通过任意用户名不输入密码即可登录数据库。
mysql> select host,user,password from mysql.user where (user) not in ('root');
+-----------------------+------+-------------------------------------------+
| host | user | password |
+-----------------------+------+-------------------------------------------+
| localhost | | |
| localhost.localdomain | | |
| % | neo | *CC4C777F1511C297751B78287D6E05345D227819 |
| % | test | *443EF031E558E317B19BAD70BDF4E25FA73A89A7 |
+-----------------------+------+-------------------------------------------+
4 rows in set (0.00 sec)
mysql> select host,user,password from mysql.user where (user) not in ('root','neo','test');
+-----------------------+------+----------+
| host | user | password |
+-----------------------+------+----------+
| localhost | | |
| localhost.localdomain | | |
+-----------------------+------+----------+
2 rows in set (0.00 sec)
解决方法:删除匿名用户。
mysql> delete from mysql.user where (user) not in ('root','neo','test');
Query OK, 2 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
之后新创建的用户即可正常登录到数据库
[root@localhost software]# ./bin/mysql -uneo -p'Mysql#2015'
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.48-log production environment
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show grants;
+-----------------------------------------------------------------+
| Grants for neo@% |
+-----------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'neo'@'%' IDENTIFIED BY PASSWORD |
| GRANT SELECT, INSERT, DELETE, CREATE ON `fire`.* TO 'neo'@'%' |
+-----------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> create user neo identified by 'Mysql#2015'; Query OK, 0 rows affected (0.00 sec)
mysql> grant select,create,update,delete on fire.* to neo; Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
--使用新用户登录报错
[root@localhost data]# ./bin/mysql -u neo -p"Mysql#2015"
ERROR 1045 (28000): Access denied for user 'neo'@'localhost' (using password: YES)
--但是不输入密码却可以登录
[root@localhost software]# ./bin/mysql -uneo
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.5.48-log production environment
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show grants;
+--------------------------------------+
| Grants for @localhost |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+
1 row in set (0.00 sec)
报错原因:Mysql使用源码安装后,数据库中存在匿名用户,可以通过任意用户名不输入密码即可登录数据库。
mysql> select host,user,password from mysql.user where (user) not in ('root');
+-----------------------+------+-------------------------------------------+
| host | user | password |
+-----------------------+------+-------------------------------------------+
| localhost | | |
| localhost.localdomain | | |
| % | neo | *CC4C777F1511C297751B78287D6E05345D227819 |
| % | test | *443EF031E558E317B19BAD70BDF4E25FA73A89A7 |
+-----------------------+------+-------------------------------------------+
4 rows in set (0.00 sec)
mysql> select host,user,password from mysql.user where (user) not in ('root','neo','test');
+-----------------------+------+----------+
| host | user | password |
+-----------------------+------+----------+
| localhost | | |
| localhost.localdomain | | |
+-----------------------+------+----------+
2 rows in set (0.00 sec)
解决方法:删除匿名用户。
mysql> delete from mysql.user where (user) not in ('root','neo','test');
Query OK, 2 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
之后新创建的用户即可正常登录到数据库
[root@localhost software]# ./bin/mysql -uneo -p'Mysql#2015'
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.48-log production environment
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show grants;
+-----------------------------------------------------------------+
| Grants for neo@% |
+-----------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'neo'@'%' IDENTIFIED BY PASSWORD
| GRANT SELECT, INSERT, DELETE, CREATE ON `fire`.* TO 'neo'@'%' |
+-----------------------------------------------------------------+
2 rows in set (0.00 sec)
用户
登录
密码
数据
数据库
输入
源码
原因
可以通过
方法
用户名
可设
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网金融监管科技数据
今日互联网科技
互联网科技资迅
金融科技 互联网金融
华宇互联网科技
期待互联网科技
紫鲸互联网科技
互联网科技的英文
易通互联网络科技有限公司
团飞科技与伯堂互联网服务平台
千方科技属于互联网企业吗
华夏互联网科技业
互联网科技大赛获奖感言
互联网科技如何创业
每天都有哪些好的互联网科技
城市宝互联网科技有限公司
广州燕处互联网科技有限公司
互联网界的黑科技
互联网公司属于科技吗
北京军民互联网科技公司
科技互联网企业
互联网科技行业发展
互联网和科技创新
互联网科技logo
互联网高科技企业
海南科技产业互联网平台
金融科技与互联网金融相同和不同
九思连强互联网电子科技有限公司
悟空问答互联网科技
科技美学互联网 艺术