Accessing MySQL from Python 3: Access denied for user

前端 未结 8 1642
鱼传尺愫
鱼传尺愫 2021-01-12 05:16

I tried to access MySQL from Python 3.3 with the following methods:

import mysql.connector

config = {
  \'user\': \'###\',
  \'password\': \'******\',
  \'h         


        
8条回答
  •  生来不讨喜
    2021-01-12 05:30

    I was having this problem when I was trying to transfer data from a python script to a MySQL database on a Raspberry Pi.

    When you initially install MySQL it sets you up as the user 'root' with whatever password you enter. If you changed the security settings afterwards to have strong passwords (like I did) your password must have uppercase, lowercase, digit and special characters.

    This may be what's throwing an error when you try to connect to the database.

    To remedy this:

    Log in to MySQL: sudo mysql --user=root

    Delete the root user: DROP USER 'root'@'localhost'; Create a new user: CREATE USER 'root'@'localhost' IDENTIFIED BY 'password'; Give the user all permissions: GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;

提交回复
热议问题