# Mysql.connector issue

**URL:** <https://forum.freecodecamp.org/t/mysql-connector-issue/468952>\
**Category:** Curriculum Help\
**Tags:** python\
**Created:** [July 12, 2021, 12:57pm UTC](https://forum.freecodecamp.org/t/mysql-connector-issue/468952 "2021-07-12T12:57:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DB1](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@DB1](https://forum.freecodecamp.org/u/DB1)\
**Post date:** [July 12, 2021, 12:57pm UTC](https://forum.freecodecamp.org/t/mysql-connector-issue/468952/1 "2021-07-12T12:57:16Z")

</div>

I am trying to connect MySQL(8.0.25) and python(3.9.6) using mysql.connector but getting error.  
Error:

```js
mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 

```

Code:

```js
import mysql.connector as sql 
s =sql.connect(host='localhost',user='root', password='<correct password>',database='<existing database>')

```

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:

```js
mysql>Select current_user;

```

Output:

```js
+----------------+
| current_user |
+----------------+
| root@localhost |
+----------------+

```

Thanks in advance.  
Kindly help me out as I tried but couldn’t solve it.

---

<div class="post-metadata">

**Author:** ![DB1](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@DB1](https://forum.freecodecamp.org/u/DB1)\
**Post date:** [July 20, 2021, 8:30am UTC](https://forum.freecodecamp.org/t/mysql-connector-issue/468952/2 "2021-07-20T08:30:06Z")

</div>

Eagerly waiting for someone to help me out.

---

<div class="post-metadata">

**Author:** ![gdennci](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/gdennci/32/225322_2.png) [@gdennci](https://forum.freecodecamp.org/u/gdennci)\
**Post date:** [July 20, 2021, 2:01pm UTC](https://forum.freecodecamp.org/t/mysql-connector-issue/468952/3 "2021-07-20T14:01:26Z")

</div>

Hey DB1,

you can format your code in the forum so it becomes more readable for others.  
Here is a nice tutorial that tells you how you can do that:

> [@Forum Code Formatting](https://forum.freecodecamp.org/t/forum-code-formatting/25574):
>
> This post is modeled on [Markdown Code Formatting - Guide - The freeCodeCamp Forum](http://forum.freecodecamp.com/t/markdown-code-formatting/18391), but modified for the slight differences between the Forum and Gitter. If you are interested in using Spoiler blocks, check this post: [Spoilers](http://forum.freecodecamp.com/t/forum-tip-add-spoilers-when-showing-code-samples/21253?u=jacksonbates). You can post code in two ways. Single word/line snippets can be handled inline. Multiple lines should be handled in code blocks: Inline Wrap your code in a single back ticks: Example: Code Blocks Wrap your code in triple back ticks, with new lines between t…

To your question. I guess you forgot to add the `database` parameter to your `sql.connect()` call.

best  
Dennis

---

<div class="post-metadata">

**Author:** ![DB1](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@DB1](https://forum.freecodecamp.org/u/DB1)\
**Post date:** [July 20, 2021, 5:41pm UTC](https://forum.freecodecamp.org/t/mysql-connector-issue/468952/4 "2021-07-20T17:41:02Z")

</div>

I have formatted the post and also added database argument. It gives the same error even after adding database name which exists. Kindly help me out.

---

<div class="post-metadata">

**Author:** ![gdennci](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/gdennci/32/225322_2.png) [@gdennci](https://forum.freecodecamp.org/u/gdennci)\
**Post date:** [July 21, 2021, 8:33am UTC](https://forum.freecodecamp.org/t/mysql-connector-issue/468952/5 "2021-07-21T08:33:41Z")

</div>

Hey DB1,

that’s the point where I would check with wireshark what connecting stinrg gets used by your code to connect or the MySQL service. But I guess that’s not an option for you?

Plan b would be to debug into the `sql.connect` function call and to find out how the connection that the mysql library creates looks like. Do you know how you can debug Python code?

If not, please tell us what IDE or code edtor you use. So maybe we can get you started into this road.

Debugging is a very important skill that you will need as a software developer. So the sooner you learn it, the better. 🙂

Sorry that there is no immediate suggestion what is wrong with your code or setup. We can only speculate because we have not enough information to really figure it out.

best  
Dennis

---

<div class="post-metadata">

**Author:** ![DB1](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@DB1](https://forum.freecodecamp.org/u/DB1)\
**Post date:** [July 21, 2021, 3:15pm UTC](https://forum.freecodecamp.org/t/mysql-connector-issue/468952/6 "2021-07-21T15:15:58Z")

</div>

I don’t know how to debug. Will need help in this regard too. I am using Python IDLE 3.9 64 bit, downloaded from official Python website [python.org](http://python.org).

---

<div class="post-metadata">

**Author:** ![gdennci](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/gdennci/32/225322_2.png) [@gdennci](https://forum.freecodecamp.org/u/gdennci)\
**Post date:** [July 22, 2021, 8:16am UTC](https://forum.freecodecamp.org/t/mysql-connector-issue/468952/7 "2021-07-22T08:16:11Z")

</div>

Oh, to be honest I have never heard about Python IDLE. I can only help you with instructions for VsCode and Intellij & PyCharm.

But I found this article that explains how you can debug with Python IDLE:

[https://www.cs.uky.edu/~keen/help/debug-tutorial/debug.html](https://www.cs.uky.edu/~keen/help/debug-tutorial/debug.html)

Try that out. If it doesn’t work I would suggest that you install VsCode with the required Python Plugin.

Here is a nice Post that explains how you can install all necessary plugins for VsCode:

[https://www.cs.uky.edu/~keen/help/debug-tutorial/debug.html](https://www.cs.uky.edu/~keen/help/debug-tutorial/debug.html)

Perhaps a few side notes about VsCode. VsCode is a code editor that supports a plethora of Plugins. It is one of the most popular code editors and supports many programming languages. It is also completely free and supported under Windows, Linux and MacOs.

It might be a good idea to use VsCode if you want to make programming your profession at some point. I worked with different programming languages using VsCode in different companies. It hasn’t failed me yet. 🙂

best  
Dennis

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [January 20, 2022, 8:16pm UTC](https://forum.freecodecamp.org/t/mysql-connector-issue/468952/8 "2022-01-20T20:16:36Z")

</div>

Closed on January 20, 2022, 8:16pm UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
