soxidus / Boardgame-Bot

A Boardgame Bot for your Telegram group to plan/manage gamenights and suggest games to play.
MIT License
2 stars 0 forks source link

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) #42

Closed karacolada closed 5 years ago

karacolada commented 5 years ago

When issuing a command with the bot, it fails with:

Traceback (most recent call last): File "/home/karacol/.local/lib/python3.6/site-packages/telegram/ext/dispatcher.py", line 279, in process_update handler.handle_update(update, self) File "/home/karacol/.local/lib/python3.6/site-packages/telegram/ext/commandhandler.py", line 173, in handle_update return self.callback(dispatcher.bot, update, *optional_args) File "/home/karacol/git/Boardgame-Bot/src/commands.py", line 280, in spiele if check_user(update.message.chat_id): File "/home/karacol/git/Boardgame-Bot/src/database_functions.py", line 171, in check_user result_user = search_single_entry(choose_database("auth"), "users", "id", user) File "/home/karacol/git/Boardgame-Bot/src/database_functions.py", line 22, in choose_database database=config['MySQL Auth']['database'] File "/home/karacol/.local/lib/python3.6/site-packages/mysql/connector/init.py", line 179, in connect return MySQLConnection(args, kwargs) File "/home/karacol/.local/lib/python3.6/site-packages/mysql/connector/connection.py", line 95, in init self.connect(kwargs) File "/home/karacol/.local/lib/python3.6/site-packages/mysql/connector/abstracts.py", line 716, in connect self._open_connection() File "/home/karacol/.local/lib/python3.6/site-packages/mysql/connector/connection.py", line 207, in _open_connection self._do_handshake() File "/home/karacol/.local/lib/python3.6/site-packages/mysql/connector/connection.py", line 99, in _do_handshake packet = self._socket.recv() File "/home/karacol/.local/lib/python3.6/site-packages/mysql/connector/network.py", line 243, in recv_plain raise errors.InterfaceError(errno=2013) mysql.connector.errors.InterfaceError: 2013: Lost connection to MySQL server during query

I tried connecting to the auth database through the docker container with

docker exec -it auth_db bash
mysql -u kara -p
Enter password:

And then the error in the title popped up: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

When googling, I found that it most likely means that the mysql service is not running. When trying to start it with service mysql restart, I get mysql: unrecognized service. The package mysql is installed, just like all the mariadb packages. service --status-all lists no mysql/mariadb service, it doesn't seem to be available. @soxidus, did you do anything to your docker containers after docker-compose up -d? Am I missing something here?

karacolada commented 5 years ago

Fixed by executing docker-entrypoint.sh in auth_db container. Shouldn't this script run automatically at container startup?

karacolada commented 5 years ago

Funny enough, the data_db worked perfectly without doing anything. Only the auth_db needed to be fixed.

soxidus commented 5 years ago

in Commit b01e8b8f4a746ed86da3c2f9a0735086b7e5224b it should work

karacolada commented 5 years ago

yup, it does!

karacolada commented 5 years ago

Actually, it doesn't. On a clean docker environment, when setting up auth_db for the first time, another execution of ./docker_entrypoint.sh is needed. No idea why...

karacolada commented 5 years ago

Traceback (most recent call last): File "/home/karacol/.local/lib/python3.6/site-packages/mysql/connector/network.py", line 485, in open_connection socket.SOL_TCP) File "/usr/lib/python3.6/socket.py", line 745, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/karacol/.local/lib/python3.6/site-packages/telegram/ext/dispatcher.py", line 279, in process_update handler.handle_update(update, self) File "/home/karacol/.local/lib/python3.6/site-packages/telegram/ext/commandhandler.py", line 173, in handle_update return self.callback(dispatcher.bot, update, *optional_args) File "/home/karacol/git/Boardgame-Bot/src/commands.py", line 279, in spiele if check_user(update.message.chat_id): File "/home/karacol/git/Boardgame-Bot/src/database_functions.py", line 184, in check_user result_user = search_single_entry(choose_database("auth"), "users", "id", user) File "/home/karacol/git/Boardgame-Bot/src/database_functions.py", line 22, in choose_database database=config['MySQL Auth']['database'] File "/home/karacol/.local/lib/python3.6/site-packages/mysql/connector/init.py", line 179, in connect return MySQLConnection(args, kwargs) File "/home/karacol/.local/lib/python3.6/site-packages/mysql/connector/connection.py", line 95, in init self.connect(kwargs) File "/home/karacol/.local/lib/python3.6/site-packages/mysql/connector/abstracts.py", line 716, in connect self._open_connection() File "/home/karacol/.local/lib/python3.6/site-packages/mysql/connector/connection.py", line 206, in _open_connection self._socket.open_connection() File "/home/karacol/.local/lib/python3.6/site-packages/mysql/connector/network.py", line 501, in open_connection errno=2003, values=(self.get_address(), _strioerror(err))) mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'auth_db:3306' (-2 Name or service not known)

karacolada commented 5 years ago

Closing this because it has a wrong error message - I was just too stupid to try and connect to mariadb instead of mysql. Opening a clean new issue.