| [ Web Proxy ] |
| Viewing: https://thepythoncode.com/code/connect-to-a-remote-mysql-server-in-python | [Back] [Original] |
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;
Ethical Hacking with Python EBook
Web Security with Python EBook
Cryptography with Python EBook
Practical Python PDF Processing EBook
Real-Time Traffic Monitoring System with YOLOv9 eBook
Mastering YOLO: Build an Automatic Number Plate Recognition System
2026 The Python Code. All rights reserved.
| Web Proxy Viewer | New URL | Original Page |