报错C:\Users\Administrator\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Administrator/PycharmProjects/pythonProject/main.py Traceback (most recent call last): File "C:/Users/Administrator/PycharmProjects/pythonProject/main.py", line 3, in <module> conn = pymysql.connect(host='localhost', user='root', password='password') File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\pymysql\connections.py", line 352, in __init__ self.connect() File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\pymysql\connections.py", line 636, in connect self._request_authentication() File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\pymysql\connections.py", line 911, in _request_authentication auth_packet = self._read_packet() File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\pymysql\connections.py", line 729, in _read_packet packet.raise_for_error() File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\pymysql\protocol.py", line 221, in raise_for_error err.raise_mysql_exception(self._data) File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\pymysql\err.py", line 143, in raise_mysql_exception raise errorclass(errno, errval) pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")
时间: 2023-07-08 18:51:23 浏览: 410
PyCharm-错误-找不到指定文件python.exe的解决方法
5星 · 资源好评率100%
这个错误提示是因为连接MySQL数据库时,用户名或密码不正确,你需要检查一下你的用户名和密码是否正确。同时,也需要确保你的MySQL服务器已经启动,并且允许远程连接。
如果你忘记了MySQL的用户名和密码,可以尝试使用以下命令来重置密码:
1. 停止MySQL服务
```
sudo service mysql stop
```
2. 以跳过授权方式启动MySQL
```
sudo mysqld_safe --skip-grant-tables --skip-networking &
```
3. 使用root用户登录MySQL
```
mysql -u root
```
4. 切换到mysql数据库
```
use mysql;
```
5. 更新root用户的密码
```
update user set authentication_string=password('your_new_password') where user='root' and Host ='localhost';
```
6. 刷新权限
```
flush privileges;
```
7. 退出MySQL并重新启动服务
```
exit;
sudo service mysql start
```
然后,你可以使用新的密码来连接你的MySQL数据库了。
阅读全文