search
HomeDatabaseMysql TutorialMYSQL ERROR 1045 (28000): Access denied for user (using pass_MySQL

bitsCN.com 第一种方法: 推荐
错误描述: Mysql中添加用户之后可能出现登录时提示ERROR 1045 (28000): Access denied for user的错误.

原因分析: 在mysql.user表中可能出现user为空的记录,如:

mysql> select host,user from user;
+------------------+------+
| host | user |
+------------------+------+
| % | test |
| localhost | |
| localhost | root |
+------------------+------+
3 rows in set (0.00 sec)

解决 办法: 删除这些为空的用户或者更新为其他用户名

删除user.user中值为NULL的,或更新NULL为test

1)delete from user where user is NULL
2)update user set user='test' where user is NULL

意外的情况: 如果上述方法没有效果,依然出现空用户,则可以利用图形化用户client删除.

第二种方法:linux下
开场白:解决LINUX问题是一种乐趣,当然,能遇到问题就是上天赐的享受幸福的机会。
这次使用的是Mandriva2008spring。
因为要搞一个项目,所以需要安装MySql,以往安装MySql都是非常顺利的,尤其MySql提供的rmp包,只需双击下就可以搞定~但不知道什么时候,MYSQL ERROR 1045 (28000): Access denied for user (using password: YES),这个拒绝访问问题变得非常广泛。
百度了一下,没有现成的解决方法,唯有找出其问题所在了。
解决问题思路:
第一步,先使用跳过受权表访问,命令如下:mysqld_safe --user=mysql --skip-grant-tables --skip-networking & (当然,在这之前,先停止mysql服务的运行)。
第二步,mysql -uroot mysql 登录mysql。
第三步,访问mysql数据库下的user表。在我的机器上,mysql> select * from user; 得到的,竟然是
Empty set (0.00 sec)。这说明了,我的mysql没有任何可以访问的用户。知道了这问题所在,解决起来就简单了。
第四步,mysql> INSERT INTO user(host, user, password, select_priv, insert_priv, update_priv) VALUES ('localhost', 'username', PASSWORD(‘yourpassword'), 'Y', 'Y','Y');
Query OK, 1 row affected, 3 warnings (0.00 sec)
返回成功,没问题。嘿嘿~~~就这么简单。
第五步,测试,再重启下mysql服务,正常登录,成功!!!

提示:mysql系统中的mysql数据库,存储的是系统数据,像这里的user表存储的是用户信息及其访问权限,还有其他,例如你要新建一个数据库mydb,这数据库有用户me管理的话,mysql数据库里面的db表就会存储相关信息。废话步多说了。

下面是windows 的解决方法:
但如果我们用虚拟主机管理系统开启的用户,而且用户数比较多的时候,好像也不是好办法。

我使用重新安装了mysql,然后进入虚拟主机,逐个删除,重新开数据库,操作之前一定要备份好原来的data目录,最后覆盖下空间数据库就可以了。
bitsCN.com

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQL: String Data Types and ENUMs?MySQL: String Data Types and ENUMs?May 13, 2025 am 12:05 AM

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

MySQL BLOB: how to optimize BLOBs requestsMySQL BLOB: how to optimize BLOBs requestsMay 13, 2025 am 12:03 AM

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Adding Users to MySQL: The Complete TutorialAdding Users to MySQL: The Complete TutorialMay 12, 2025 am 12:14 AM

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

Mastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMastering MySQL String Data Types: VARCHAR vs. TEXT vs. CHARMay 12, 2025 am 12:12 AM

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

MySQL: String Data Types and Indexing: Best PracticesMySQL: String Data Types and Indexing: Best PracticesMay 12, 2025 am 12:11 AM

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor