#1045 无法登录 MySQL 服务器

来源:互联网 发布:九型人格出生日期算法 编辑:程序博客网 时间:2024/05/18 02:22

今天遇到了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.

  • Using WAMP, left click your WAMP icon located at the bottom right of your desktop and click on MySQL Console.
  • Guide to accessing MySQL using XAMPP
  • Guide to accessing MySQL using MAMP.

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服务窗口启动它。如果以手动方式启动了服务器,能够像正常情形下一样使用命令。




 

0 0
原创粉丝点击