Python Forum
A combination of Python and MySql
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A combination of Python and MySql
#1
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.
Reply
#2
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.
Reply
#3
Photo 
in php my admin has permission granted to admin, ALL PRIVILEGES permission, User account 'admin' @ 'localhost'

Can you throw sreens here?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysql and mysql.connector error lostintime 2 612 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Mysql error message: Lost connection to MySQL server during query tomtom 6 15,677 Feb-09-2022, 09:55 AM
Last Post: ibreeden
Question Debian 11 Bullseye | Python 3.9.x | pip install mysql-connector-python-rf problems BrandonKastning 4 6,572 Feb-05-2022, 08:25 PM
Last Post: BrandonKastning
  Python and MySql ogautier 8 3,250 May-20-2021, 11:10 PM
Last Post: Pedroski55
  Python and MySQL Pedroski55 5 3,179 Mar-23-2021, 06:40 AM
Last Post: ndc85430
  Group List Elements according to the Input with the order of binary combination quest_ 19 6,240 Jan-28-2021, 03:36 AM
Last Post: bowlofred
  Python MySQL ogautier 0 2,082 Sep-03-2020, 03:54 PM
Last Post: ogautier
  Insert into mysql through python LaKhWaN 0 1,921 Aug-26-2020, 04:54 AM
Last Post: LaKhWaN
  Python mysql query help please tduckman 4 4,243 Mar-13-2020, 03:42 PM
Last Post: Marbelous
  Checking if the combination of two keys is in a dictionary? mrsenorchuck 6 3,776 Dec-04-2019, 10:35 AM
Last Post: mrsenorchuck

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020