Python Forum

Full Version: A combination of Python and MySql
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,,

I am not sure if I have started this topic in the right place, if not, please move it.
I have a problem with the connection between Python and the MySQL database. When debugging the code
import mysql.connector

con = mysql.connector.connect(user='admin',password='admin123',host='127.0.0.1',port='3306',database='admin')
Traceback (most recent call last):
  File "C:\Users\Asus\Desktop\1.py", line 6, in <module>
    db = pymysql.connect("127.0.0.1","admin","admin123","admin" )
  File "D:\Python33\lib\site-packages\pymysql\__init__.py", line 90, in Connect
    return Connection(*args, **kwargs)
  File "D:\Python33\lib\site-packages\pymysql\connections.py", line 699, in __init__
    self.connect()
  File "D:\Python33\lib\site-packages\pymysql\connections.py", line 936, in connect
    self._request_authentication()
  File "D:\Python33\lib\site-packages\pymysql\connections.py", line 1156, in _request_authentication
    auth_packet = self._read_packet()
  File "D:\Python33\lib\site-packages\pymysql\connections.py", line 1018, in _read_packet
    packet.check_error()
  File "D:\Python33\lib\site-packages\pymysql\connections.py", line 384, in check_error
    err.raise_mysql_exception(self._data)
  File "D:\Python33\lib\site-packages\pymysql\err.py", line 107, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, "Access denied for user 'admin'@'localhost' (using password: YES)")
I also tried importing pymysql and the effect was also the same

import pymysql

db = pymysql.connect("127.0.0.1","admin","admin123","admin" )

cursor = db.cursor()
Traceback (most recent call last):
  File "C:\Users\Asus\Desktop\1.py", line 5, in <module>
    db = pymysql.connect("127.0.0.1","admin","admin123","admin" )
  File "D:\Python33\lib\site-packages\pymysql\__init__.py", line 90, in Connect
    return Connection(*args, **kwargs)
  File "D:\Python33\lib\site-packages\pymysql\connections.py", line 699, in __init__
    self.connect()
  File "D:\Python33\lib\site-packages\pymysql\connections.py", line 936, in connect
    self._request_authentication()
  File "D:\Python33\lib\site-packages\pymysql\connections.py", line 1156, in _request_authentication
    auth_packet = self._read_packet()
  File "D:\Python33\lib\site-packages\pymysql\connections.py", line 1018, in _read_packet
    packet.check_error()
  File "D:\Python33\lib\site-packages\pymysql\connections.py", line 384, in check_error
    err.raise_mysql_exception(self._data)
  File "D:\Python33\lib\site-packages\pymysql\err.py", line 107, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, "Access denied for user 'admin'@'localhost' (using password: YES)")
The password and login match. Are you able to tell me something in the topic, I'm fighting the second day and I do not know what the problem may be? I will also swear that I am a layperson when it comes to python. I'm just learning it.
If this is the essence of information, then the server I have placed on a virtual machine on which Debian9 is installed, while python 3 works on windows7.
The error message says that your user doesn't have permission to access the database. You will either have to sign in with a user who does have permission, or get your user added the database's group, with read permission, and write permission if you want to change the database.
in php my admin has permission granted to admin, ALL PRIVILEGES permission, User account 'admin' @ 'localhost'

Can you throw sreens here?