0
0

More than 3 years have passed since last update.

Python3: coreserver で mysql を使う

Posted at

coreserver は共用サーバーなので、色々と制約があります。root は使えません。

ライブラリーのインストール

mkdir my-space
python3 -m pip install mysql-connector  --target ~/my-space
Collecting mysql-connector

サンプルプログラム

server_version.py
#! /usr/bin/python3
#
import sys
#
sys.path.append('/virtual/example/my-space')
import  mysql.connector
print ("*** start ***")
#
host_aa='localhost'
user_aa ='scott'
password_aa = 'tiger'
data_base = 'city'
conn = mysql.connector.connect(user=user_aa, password=password_aa, \
                              host=host_aa,database=data_base)
#
cursor = conn.cursor()
#
cursor.execute("SELECT VERSION ()")
#
row = cursor.fetchone()
print(row[0])
#
cursor.close()
conn.close()
#
print("*** end ***")

実行結果

$ ./server_version.py 
*** start ***
5.7.29-log
*** end ***
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0