Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MYSQL.CONNECTOR ERROR
#1
I am trying to connect MySQL(8.0.25) and python(3.9.6) using mysql.connector but getting error.
Error:
mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Code:
import mysql.connector as sql 
s=sql.connect(host='localhost' ,user='root', password='<correct password>',database='empl')
The password I entered is the one I use to successfully login to MySQL 8.0 Command line client.
Same code is working for pymysql.connect without any error.
I checked out the Host and User Name by logging in to MYSQL 8.0 Command Line client with my password and typing:
mysql>Select current_user;
And got the Output:
Output:
+----------------+ | current_user | +----------------+ | root@localhost | +----------------+
Thanks in advance.
Kindly help me out as I tried everything but couldn't solve it.
Looking forward for a reply.
Larz60+ write Jul-11-2021, 06:13 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please refrain from using images for code.
Reply
#2
Suspect from the documents that you must specify a database. See the MySQL connector for Python documents HERE
Reply
#3
(Jul-12-2021, 05:30 PM)jefsummers Wrote: Suspect from the documents that you must specify a database. See the MySQL connector for Python documents HERE
I even tried that out, but, unfortunately, that doesn't make any difference.

Eagerly waiting for someone to help me out.
Reply
#4
You could try pymysql. MYSQL connector seems to not play well with python 3
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#5
I second menator01's answer.

I use pymsql to collect data from my webpage database. Works amazingly fast, just 1 or 2 seconds to collect data from 168 students and write it to a results Excel file!! I am always flabbergasted! Used to take me a long time copying and pasting and sorting stuff!

import pymysql 
import openpyxl
import os

def mysqlRemote(clas, weeknr): 
    # To connect to remote MySQL database 
    conn = pymysql.connect( 
        host='123.456.789.123', 
        user='allstudents',  
        password = 'blurb', 
        db='mydb', 
        ) 
      
    cur = conn.cursor()
    
    # Select query 
    cur.execute(f"SELECT studentnr, score FROM allstudentsAnswers{clas} WHERE weeknr = '{weeknr}'") 
    output = cur.fetchall() 
      
    #for i in output: 
        #print(i) 
      
    # To close the connection 
    conn.close()
    return output
Reply
#6
(Jul-18-2021, 08:11 PM)menator01 Wrote: You could try pymysql. MYSQL connector seems to not play well with python 3
pymysql is working very well for me too. But, as per my school course, I am bound to use mysql.connector.
Reply
#7
(Jul-18-2021, 10:24 PM)Pedroski55 Wrote: I second menator01's answer.

I use pymsql to collect data from my webpage database. Works amazingly fast, just 1 or 2 seconds to collect data from 168 students and write it to a results Excel file!! I am always flabbergasted! Used to take me a long time copying and pasting and sorting stuff!

import pymysql 
import openpyxl
import os

def mysqlRemote(clas, weeknr): 
    # To connect to remote MySQL database 
    conn = pymysql.connect( 
        host='123.456.789.123', 
        user='allstudents',  
        password = 'blurb', 
        db='mydb', 
        ) 
      
    cur = conn.cursor()
    
    # Select query 
    cur.execute(f"SELECT studentnr, score FROM allstudentsAnswers{clas} WHERE weeknr = '{weeknr}'") 
    output = cur.fetchall() 
      
    #for i in output: 
        #print(i) 
      
    # To close the connection 
    conn.close()
    return output
pymysql is working very well for me too. But, as per my school course, I am bound to use mysql.connector.
Reply
#8
(Jul-19-2021, 03:40 AM)DB1 Wrote:
(Jul-18-2021, 10:24 PM)Pedroski55 Wrote: I second menator01's answer.

I use pymsql to collect data from my webpage database. Works amazingly fast, just 1 or 2 seconds to collect data from 168 students and write it to a results Excel file!! I am always flabbergasted! Used to take me a long time copying and pasting and sorting stuff!

import pymysql 
import openpyxl
import os

def mysqlRemote(clas, weeknr): 
    # To connect to remote MySQL database 
    conn = pymysql.connect( 
        host='123.456.789.123', 
        user='allstudents',  
        password = 'blurb', 
        db='mydb', 
        ) 
      
    cur = conn.cursor()
    
    # Select query 
    cur.execute(f"SELECT studentnr, score FROM allstudentsAnswers{clas} WHERE weeknr = '{weeknr}'") 
    output = cur.fetchall() 
      
    #for i in output: 
        #print(i) 
      
    # To close the connection 
    conn.close()
    return output
pymysql is working very well for me too. But, as per my school course, I am bound to use mysql.connector.
Looking forward for a reply to help me out.
Reply
#9
Someone kindly help me out!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysql and mysql.connector error lostintime 2 660 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Mysql Syntax error in pymysql ilknurg 4 2,344 May-18-2022, 06:50 AM
Last Post: ibreeden
  Mysql error message: Lost connection to MySQL server during query tomtom 6 15,971 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,663 Feb-05-2022, 08:25 PM
Last Post: BrandonKastning
  mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python ilknurg 3 5,579 Jan-18-2022, 06:25 PM
Last Post: ilknurg
  mySQL Database error not resolving. cybertooth 2 3,192 Aug-30-2021, 05:45 PM
Last Post: ibreeden
  Program stuck at mysql.connector.connect zazas321 1 2,071 Jul-29-2021, 10:49 AM
Last Post: zazas321
  pool mysql error - not catch by try\except? korenron 1 2,138 Jul-05-2021, 11:26 AM
Last Post: ibreeden
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 error from Mysql call AkaAndrew123 1 3,435 Apr-28-2021, 08:16 AM
Last Post: AkaAndrew123
  Error in Mysql Client when upgrading Django Abi 0 1,871 Sep-21-2020, 06:11 AM
Last Post: Abi

Forum Jump:

User Panel Messages

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