'전체 글'에 해당되는 글 515건

  1. 2018.11.19 PyMySQL 2

PyMySQL

Python 2018. 11. 19. 21:54 |
반응형

PyMySQL은 Python에서 MySQL사용을 도와주는 순수 Python MySQL client library이다.

 

설치 조건:

  • Python -- one of the following:
  • MySQL Server -- one of the following:
  • 설치:

    Package is uploaded on PyPI.

    You can install it with pip:

    $ python3 -m pip install PyMySQL

    관련 문서:

    Documentation is available online: https://pymysql.readthedocs.io/

    For support, please refer to the StackOverflow.



    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    import pymysql
     
    connection = pymysql.connect(host = '127.0.0.1', port = 3306, user = 'root', password = '1234', db = 'shopdb', charset = 'utf8')
    # Representation of a socket with a mysql server. The proper way to get an instance of this class is to call connect().
    # Establish a connection to the MySQL database.
     
    cursor = connection.cursor() # Create a new cursor to execute queries with
     
    sql = "select * from membertbl"
    cursor.execute(sql) # Execute a query
     
    rows = cursor.fetchall() # Fetch all the rows
    for member in rows:
        print(member)
     
    connection.close() # Closing a cursor just exhausts all remaining data.
    cs


    반응형
    Posted by J-sean
    :