#1045 无法登录 MySQL 服务器

今天遇到了1045错误,其实去年那个时候也遇到过。上次的情况是1045错误和不能通过匿名登录mysql使用了第一种方法就可以解决了,但是这次出现的情况是在命令行中居然可以匿名登录mysql,但是没有mysql这个数据库更没有mysql.user这个表,故第一种方法不能行。于是找到了第二种方法,试了试就成功了。


修改密码实际需要两步骤:

1.修改mysql数据库的密码

2.修改phpmyadmin的配置文件config.inc.php连接数据库的密码



第一种方法:


After installing a local server and trying to access phpMyAdmin, you could possibly encounter the error: #1045 Access Denied for user 'root'@'localhost' (using password: YES).

If root@localhost wasn't granted the necessary rights to access the database or you provided the wrong password, you will then encounter this error.

Following this tutorial will help guide you on bypassing this error, for any local host server using phpMyAdmin.

If you get an Error #1045 in phpMyAdmin it will look like the image below:

Step 1: Open your MySQL console.

Step 2: Enter the Provided Command Lines

If you have a password, you can ignore this part.

  • Type in: use mysql;
  • Press Enter.
  • Set your MySQL Password: UPDATE mysql.user

SET Password=PASSWORD("EnterYourPasswordHere")
WHERE User="root";

  • Replace "EnterYourPasswordHere" with your new chosen password.
  • Press Enter.
  • Flush the privileges: FLUSH PRIVILEGES;
  • Exit by typing: Exit
  • Press Enter.

Step 3: Open and edit your config.inc.php file located in your local server files

  • Using a text editor, such as Notepad++, open your config.inc.php file.
  • Go to My Computer > C Drive > (Your Local Server Folder, WAMP/MAMP/XAMPP) > APPS > PHPMYADMIN > config.inc.php
  • Find this line of code: $cfg['Servers'][$i]['password'] = ''; // MySQL password
  • Change 'password' to the new chosen password you created from Step 2.
  • Click Save.

Step 4: Access phpMyAdmin

  • You can access phpMyAdmin by going to http://localhost/phpMyAdmin/.
  • Congratulations! You are now able to access your databases.



第二种方法


如果MySQL服务器正在运行,停止它。
      如果是作为Windows服务运行的服务器,进入服务管理器:开始菜单->控制面板->管理工具->服务
      如果服务器不是作为服务而运行的,可能需要使用任务管理器来强制停止它。
3、创建1个文本文件,并将下述命令置于单一行中:
      SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPassword');
      用任意名称保存该文件。在本例中,该文件为C:\mysql-init.txt。
4、进入DOS命令提示:开始菜单->运行-> cmd
      假定你已将MySQL安装到C:\mysql。如果你将MySQL安装到了另一位置,请对下述命令进行相应的调整。
      在DOS命令提示符下,执行命令:
            C:\> C:\mysql\bin\mysqld-nt --init-file=C:\mysql-init.txt
      在服务器启动时,执行由“--init-file”选项(作用:在启动时从指定的文件中读取SQL命令)命名的文件的内容,更改根用户密码。当服务器成功启动后,应删除C:\mysql-init.txt。
5、停止MySQL服务器,然后在正常模式下重启它。如果以服务方式运行服务器,应从Windows服务窗口启动它。如果以手动方式启动了服务器,能够像正常情形下一样使用命令。




 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Penguinbupt

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值