ํฐ์คํ ๋ฆฌ ๋ทฐ
728x90
๋ฐ์ํ
๐ DB ์ ์ ํ ์คํธ ๋๊ตฌ ์์ฝ
๐งฉ ํ ์คํธ ๋์
- MariaDB (ํฌํธ 3306)
- Microsoft SQL Server (ํฌํธ 1433)
๐ง ํ ์คํธ ํญ๋ชฉ
ํ ์คํธ ์ข ๋ฅ | ์ค๋ช |
---|---|
test1 |
DB ์ ์ ํ ์ฆ์ ์ข ๋ฃ (์ฐ๊ฒฐ๋ง ํ์ธ) |
test2 |
DB ์ ์ โ ํ๋์ฝ๋ฉ๋ ์ฟผ๋ฆฌ ์คํ โ ์ข ๋ฃ |
๐งช ํ๋์ฝ๋ฉ๋ ์ฟผ๋ฆฌ (test2)
DB ํ์ | ์ฟผ๋ฆฌ |
---|---|
MariaDB | SELECT NOW() |
MSSQL | SELECT GETDATE() |
๐ ๋ช ๋ น์ด ์์
# test1 - ์ ์๋ง ํ
์คํธ (10ํ ๋ฐ๋ณต)
python test_db_loop.py test1 mariadb 127.0.0.1 3306 root mypass testdb 10
# test2 - ์ฟผ๋ฆฌ ํ
์คํธ ํฌํจ (5ํ ๋ฐ๋ณต)
python test_db_loop.py test2 mssql 127.0.0.1 1433 sa pass123 mydb 5
๐งต ๋ณ๋ ฌ ์คํ ์์ (๋ฉํฐ ํ๋ก์ธ์ค)
from multiprocessing import Process
from test_db_lib import test1_connect_only
def run_task():
test1_connect_only(
dbtype="mariadb",
host="192.168.0.10",
port="3306",
user="root",
password="mypassword",
dbname="test"
)
if __name__ == "__main__":
processes = [Process(target=run_task) for _ in range(10)]
for p in processes:
p.start()
for p in processes:
p.join()
๐ง ์ฃผ์ Python ์ฝ๋ ๊ตฌ์ฑ (test1/test2)
def test1_connect_only(dbtype, host, port, user, password, dbname):
if dbtype == "mariadb":
import pymysql
conn = pymysql.connect(
host=host, port=int(port), user=user, password=password,
database=dbname, connect_timeout=5
)
conn.close()
print("[OK] ์ ์/์ข
๋ฃ ์ฑ๊ณต")
return True
elif dbtype == "mssql":
import pyodbc
conn_str = (
f"DRIVER={{ODBC Driver 17 for SQL Server}};"
f"SERVER={host},{port};DATABASE={dbname};UID={user};PWD={password};"
f"TrustServerCertificate=yes;"
)
conn = pyodbc.connect(conn_str, timeout=5)
conn.close()
print("[OK] ์ ์/์ข
๋ฃ ์ฑ๊ณต")
return True
โ ๏ธ ์ ์ ์ฌํญ
- Windows์์๋ ๋ฐ๋์
__name__ == "__main__"
์กฐ๊ฑด๋ฌธ ์์์ ํ๋ก์ธ์ค ์คํ - DB ๊ณ์ ๋์ ์ ์ ์ ํ, ์ปค๋ฅ์ ํ ์ต๋๊ฐ ๋ฑ ํ์ธ ํ์
- ์ฟผ๋ฆฌ ์คํจ ๋๋ ๋คํธ์ํฌ ์๋ฌ๋ ๋ก๊ทธ๋ก ์ถ๋ ฅ๋จ
728x90
๊ณต์ ํ๊ธฐ ๋งํฌ
๋๊ธ
๋ฐ์ํ
๊ณต์ง์ฌํญ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
- Total
- Today
- Yesterday
๋งํฌ
TAG
- Thread
- C#.NET
- ์ค์ฟ ๋ฒ๋ค์ด๋น
- ์ธ๋ฆ๋
- C# ๊ณ ๊ธ ๊ธฐ์
- C#
- ๋ธ๋ฃจ๋ฒ๋ธ๋ค์ด๋ธํ
- PowerShell
- ๋ฆฌ๋ ์ค
- ๋์์ธํจํด
- OpenSource
- ์๊ทํฌ๋ธ๋ฃจ๋ฒ๋ธ
- ip
- Build
- ๋ธ๋ฃจ๋ฒ๋ธ๋ค์ด๋นํ
- ์๊ทํฌ
- CMake
- ์ฑ์ฐ๋ธ๋ฃจ๋ฒ๋ธ
- ReFS
- ์๋์ฐ
- DLL
- ๋ธ๋ฃจ๋ฒ๋ธ
- C
- Linux
- Windows
- C++
- ํํฌ๋ค์ด๋ธ
- ์ํธํ
- ์ ์ฃผ๋
- ํจํด
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
๊ธ ๋ณด๊ดํจ