I have a script that connects to a MySQL DB via pyMySQL
.
It works like a charm when I execute it manually from the console, but gives this output when I run this cronjob:
@reboot sudo python3 /var/www/html/ls/src/AppBundle/Command/crawl.py true > /tmp/listener.log 2>&1
Result:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 890, in connect
(self.host, self.port), self.connect_timeout)
File "/usr/lib/python3.5/socket.py", line 711, in create_connection
raise err
File "/usr/lib/python3.5/socket.py", line 702, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
Why is that? I followed all of this https://stackoverflow.com/a/15684341/1092632 w/out any success.
Any hint appreciated!
Edit
Things I tried:
connect = pymysql.connect(host=constants.HOST,
user=constants.USERNAME,
passwd=constants.PASSWORD,
db=constants.DATABASE,
charset='utf8mb4',
port=constants.PORT,
unix_socket=constants.SOCKET,
cursorclass=pymysql.cursors.DictCursor)
constants.py
# MySQL #
HOST = '127.0.0.1' // Localhost, 127.0.0.1 and public IP of Server (having bind to 0.0.0.0
USERNAME = 'admin'
PASSWORD = 'XXX'
DATABASE = 'ls_base'
PORT = '3306' // With and without ''
SOCKET = '/var/run/mysqld/mysqld.sock' // File exists