Accessing MySQL from Python 3: Access denied for user

前端 未结 8 1610
鱼传尺愫
鱼传尺愫 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:46

    You need to grant priviliges to your root user from MySQL, as your exception message said. Firstly, you login to your MySQL from the command line or from your favorite MySQL client (such as MySQL workbench.) Then you grant permission to your user (root, in this case). This link describes how to login to MySQL from the console, for example,

    mysql -h localhost -u root -p

    then you need to grant priviliges to user root, for example,

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';
    

    which gives full permissions for all databases from any host (%) to root using a password. You need to be careful if this server is accessible from internet while granting permissions.

提交回复
热议问题