I wrote a Python program that users can send posts, signup and login. I used MySQL in this app. When I try to open MySQL with localhost
it works, But when I insert my IP Address it does not work. I use Ubuntu and ifconfig
returns a lot of addresses. I tried all of them but did not work. MySQL returns : Can't connect to MySQL server on (IP):3306' (113)
. What can I do?
Python code starting is like:
import tkinter as tk
from tkinter import messagebox
import mysql.connector
DB_HOST = 'My IP Address'
DB_USER = 'My User Name'
DB_PASSWORD = 'My Password'
DB_NAME = 'My Database'
# Connection Here :
db_connection = mysql.connector.connect(
host=DB_HOST,
user=DB_USER,
password=DB_PASSWORD,
database=DB_NAME
)
db_cursor = db_connection.cursor()
2
Answers
localhost is 127.0.0.1.
This is defined in your /etc/hosts file.
MySQL however behaves differently. Read the comment by erik258 below.
Error 113 indicates, that the client can’t connect to the server, since there is no physical route to the server.
Possible reasons: