Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commite31a14f

Browse files
committed
added remote mysql connection tutorial
1 parent5654c46 commite31a14f

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
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.
Lines changed: 1 addition & 0 deletions
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)
Lines 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 ALLON*.* TO'python-user'@'%';
5+
FLUSH PRIVILEGES;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
importmysql.connectorasmysql
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!
Lines 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)

[8]ページ先頭

©2009-2025 Movatter.jp