Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e31a14f

Browse filesBrowse files
committed
added remote mysql connection tutorial
1 parent 5654c46 commit e31a14f
Copy full SHA for e31a14f

File tree

Expand file treeCollapse file tree

5 files changed

+23
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+23
-0
lines changed
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,6 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
102102

103103
- ### Database
104104
- [How to Use MySQL Database in Python](https://www.thepythoncode.com/article/using-mysql-database-in-python). ([code](database/mysql-connector))
105+
- [How to Connect to a Remote MySQL Database in Python](https://www.thepythoncode.com/article/connect-to-a-remote-mysql-server-in-python). ([code](database/connect-to-remote-mysql-server))
105106

106107
For any feedback, please consider pulling requests.
Collapse file
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Connect to a Remote MySQL Database in Python](https://www.thepythoncode.com/article/connect-to-a-remote-mysql-server-in-python)
Collapse file
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* '%' means from any where in the world*/
2+
CREATE USER 'python-user'@'%' IDENTIFIED BY 'Password1$';
3+
/* grant all privileges to the user on all databases & tables available in the server */
4+
GRANT ALL ON *.* TO 'python-user'@'%';
5+
FLUSH PRIVILEGES;
Collapse file
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import mysql.connector as mysql
2+
3+
# enter your server IP address/domain name
4+
HOST = "x.x.x.x" # or "domain.com"
5+
# database name, if you want just to connect to MySQL server, leave it empty
6+
DATABASE = "database"
7+
# this is the user you create
8+
USER = "python-user"
9+
# user password
10+
PASSWORD = "Password1$"
11+
# connect to MySQL server
12+
db_connection = mysql.connect(host=HOST, database=DATABASE, user=USER, password=PASSWORD)
13+
print("Connected to:", db_connection.get_server_info())
14+
15+
# enter your code here!
Collapse file
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mysql-connector-python

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.