Python PyMySQL MariaDB - Errno 111 Connection refused

1 odpovědí
28.07.2017 napsal Ctiborek dotaz do kategorie programovani 8 / 9

Python PyMySQL MariaDB - Errno 111 Connection refused

Vyřešeno

programovani python mysql databaze

Dobrý den, používám CentOS 7 a MariaDB server a nemohu se přes Python3.4 s knihovnou PyMySQL připojit k databázi MySQL, ačkoliv jsou údaje správné. Opravdu už nevím co s tím.

con = mysql.connect(host='localhost', user='root', passwd='pass', db='db')
    with con:
        cur = con.cursor()
[root@server]# python3.4 /var/mariadb-test.py Traceback (most recent call last): File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 916, in connect **kwargs) File "/usr/lib64/python3.4/socket.py", line 516, in create_connection raise err File "/usr/lib64/python3.4/socket.py", line 507, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/var/mariadb-test.py", line 42, in fillerLoop() File "/var/mariadb-test.py", line 19, in fillerLoop con = mysql.connect(host='localhost', user='root', passwd='pass', db='db') File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/__init__.py", line 90, in Connect return Connection(*args, **kwargs) File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 706, in __init__ self.connect() File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 963, in connect raise exc pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)") [root@server]# mysql -u root -p --port=3307 --protocol=tcp Enter password: ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (111) [root@server]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2937 Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> table -> Ctrl-C -- exit! Aborted [root@server]# mysql -u root -p --port=3308 --protocol=tcp Enter password: ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (111) [root@server]# netstat -tulpn | grep mysql tcp 0 0 192.168.20.254:3306 0.0.0.0:* LISTEN 9297/mysqld [root@server]# systemctl restart mariadb

01.08.2017 odpověděl OL3G Moderátor
Zkontrolováno

Ahoj, zkus zjistit socket pro MySQL server: mysqladmin -u root -p variables | grep socket a doplnit pak socket do mysql.connect

con = mysql.connect(host='localhost', user='root', passwd='pass', db='db', unix_socket="/var/lib/mysql/mysql.sock")
    with con:
        cur = con.cursor()

Tento web používá k poskytování služeb, personalizaci reklam a analýze návštěvnosti soubory cookie. Používáním tohoto webu s tím souhlasíte. Další informace