question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improper error shown - (2003, "Can't connect to MySQL server on 'localhost'")

See original GitHub issue

Describe the bug

Well I formatted my pc and had to reinstall all the stuff and while I started working with my code I started receiving error (2003, "Can't connect to MySQL server on 'localhost'") I was not expecting that as my code worked flawless and at that time my discord bot which uses the same code was up and running well. So after two hours of going through all code I found that I had added db parameter in aiomysql.create_pool and I had forgot to create a database with the db mentioned there so that was the problem! So what I want is it should throw error that db is not found rather than (2003, "Can't connect to MySQL server on 'localhost'")

To Reproduce

I am running latest version of python 3.10 and pip installed aiomysql

Just dont make a database and try creating aiomysql.create_pool object with mentioning db you will get the error!

I used following code:

import asyncio
import aiomysql

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)


async def test_example():
    try:
        conn = await aiomysql.create_pool(host='localhost', port=3306, user='user', password='pass',loop=loop,db="uncreated_db")
    except Exception as e:
        print(e)

loop.run_until_complete(test_example())

Expected behavior

Will throw this error : (2003, "Can't connect to MySQL server on 'localhost'")

Logs/tracebacks

Will throw this error : ``(2003, "Can't connect to MySQL server on 'localhost'")``

Python Version

$ Python 3.10.4

aiomysql Version

$ python -m pip show aiomysql

PyMySQL Version

1.0.2

SQLAlchemy Version

1.0.2

OS

Windows

Database type and version

MySQL : 8.0.29

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Nothing4Youcommented, Aug 23, 2022

#839 should resolve this.

0reactions
AndreMPCostacommented, Aug 16, 2022

Why do we have this bit of code:

  except Exception as e:
      if self._writer:
          self._writer.transport.close()
      self._reader = None
      self._writer = None
      raise OperationalError(2003,
                             "Can't connect to MySQL server on %r" %
                             self._host) from e

Instead of raising the original exception? We lose all the info and the error code (auth failed for 1045 for example, 1049 database not found, etc).

This approach does not make much sense, putting everything as an Operational Error 2003 code.

https://github.com/aio-libs/aiomysql/blob/814d07266e0ac16eee0ca25f97691f6c7d4db4af/aiomysql/connection.py#L553

Read more comments on GitHub >

github_iconTop Results From Across the Web

B.3.2.2 Can't connect to [local] MySQL server
The error (2003) Can't connect to MySQL server on ' server ' (10061) indicates that the network connection has been refused. You should...
Read more >
Can't connect to MySQL server on 'localhost' (10061) solved
Transcript · ERROR 2003 (HY000): Can't connect to MySQL server on ' localhost ' (10061 "Unknown error ") - Debugged · PHP -...
Read more >
Can't connect to mysql server [solution] error 2003 ... - YouTube
Could not connect to MySQL : can't connect to MySQL server on ' localhost '(10061)(Code2003). cant connect to mysql server on ' localhost...
Read more >
Can't Connect to MySQL Server on 'localhost' (10061)
This is about the causes of the “error 2003 (hy000) can't connect to MySQL server on 'localhost' (10060)” error and different ways to...
Read more >
6.2.17 Troubleshooting Problems Connecting to MySQL
mysql ERROR 2003: Can't connect to MySQL server on ' host_name ' (111) $> mysql ... it means that you have an incorrect...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found