MySQL 1045 Login failed

 When you log in to the MySQL database and get: Error 1045 (as shown in the figure below), it means that the user name or password you entered is incorrect and access is denied. The easiest solution is to uninstall and reinstall the MySQL database, but the disadvantage of this is that The information in the previous database will be lost, if you do not want to reinstall, then you need to retrieve the password or reset the password. There should be a variety of solutions. Here I recommend that you use a method that is passed through the principle and easy to operate, which is suitable for Windows and Linux platforms. 

The MySQL 1045 error is shown in the figure:

[plain]  view plain copy  
 
 print ?
  1. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)  


solution:

1.   Stop the service: stop the MySQL service;

2.   Skip verification: Modify the my.ini configuration file in the MySQL installation directory to skip the permission check when logging in;

3.   Change the password: Start the MySQL service and log in to MySQL . At this time, you are prompted to enter a password. Enter any password and press Enter to enter MySQL . Then modify the password of the root user through SQL statements ;

4.   Restart the service: delete the skip permission statement added in the my.ini file or add a # comment. Restart the service and log in with the modified password.

Windows system specific operation:

1.   Stop the service:

Method 1 : Use the dos command net stop mysql ; in this way, the MySQL service must be an installed service, otherwise

There will be an invalid service name, then you can use the second method.

Method 2 : Enter [Control Panel] --> [Administrative Tools]  --> [Services], find the MySQL service, and click Stop on the left.

2.   Skip verification:

进入MySQL的安装路径(以默认安装路径为例)C:\Program Files\MySQL\MySQL Server 5.1\,找到my.ini配置文件(些文件记录MySQL的常规参数,每次启动服务都会先加载此文件),在my.ini配置文件的最后一行加入skip_grant_tables,此语句可以忽略登录检查。

3、  修改密码:

启动MySQL服务,进入dos环境,输入mysql -u root -p登录MySQL(如果安装时没有勾选添加

环境变量,需要先使用cd命令进入MySQL安装目录),此时提示输入密码,输入任意密码回车即可进入MySQL,出现mysql>控制符,此时表示已经成功登录MySQL

mysql> USEmysql   (将数据库切换至mysql库中)

mysql> UPDATE user SET password=PASSWORD(‘newpswd’)WHERE user=’root’          (修改密码)

password函数为MySQL内部函数,其中newpswd为修改后的新密码。

4、  重启服务:

my.ini文件中加入的跳过权限语句删除或加#号注释。重启服务,使用修改后的密码登录即可。

 

Linux系统具体操作:

1、  停止服务:

执行:/etc/init.d/mysqlstop

(你的机器不一定是/etc/init.d/mysql也可能是/etc/init.d/mysqld,可以通过find命令查找)。

2、  跳过验证:

执行:/usr/local/mysql/bin/mysqld_safe--skip-grant-tables >/dev/null 2>&1 &

(If the location of mysqld_safe is different, it needs to be modified. If it is not clear, you can use the find command to find it).

3.   Change the password:

implement:

/usr/local/mysql/bin/ mysql -u root mysql       (login mysql )

mysql>  UPDATE  user SET  password= PASSWORD ('newpswd') WHERE  user='root'   (change password)

mysql>flush privileges      (  flush MySQL privilege-related tables)

mysql>exit                          (exit MySQL )

4.   Restart the service:

implement:

killall mysqld                       (kill the mysql process)

/etc/init.d/mysql start       (start mysql service)

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326605536&siteId=291194637