Code for How to Connect to a Remote MySQL Database in Python Tutorial


View on Github

remote_mysql_connector.py

import mysql.connector as mysql

# enter your server IP address/domain name
HOST = "x.x.x.x" # or "domain.com"
# database name, if you want just to connect to MySQL server, leave it empty
DATABASE = "database"
# this is the user you create
USER = "python-user"
# user password
PASSWORD = "Password1$"
# connect to MySQL server
db_connection = mysql.connect(host=HOST, database=DATABASE, user=USER, password=PASSWORD)
print("Connected to:", db_connection.get_server_info())
# enter your code here!

config.sql

/* '%' means from any where in the world*/
CREATE USER 'python-user'@'%' IDENTIFIED BY 'Password1$';
/* grant all privileges to the user on all databases & tables available in the server */
GRANT ALL ON *.* TO 'python-user'@'%';
FLUSH PRIVILEGES;


pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy