[python][자료구조] python anaconda 에서 mysql 접속 

 

Connecting to MySQL

Anaconda Enterprise enables you to easily connect to a MySQL relational database management system (RDBMS), to access the data stored in it.

Before you can do so, however, you’ll need to install the mysql-connector-python conda package, which contains the Python driver for communicating with MySQL servers:

 conda install -c anaconda mysql-connector-python 
conda install -c anaconda mysql-connector-python

NOTE: Any packages you install from the command line are available during the current session only. If you want them to persist, add them to the project’s anaconda-project.yml file. For more information, see Developing a project.

You can then use code such as this to connect to MySQL from within a notebook session:

import mysql.connector as mysql
import json


# Get credentials from Kubernetes. The credentials were setup as a dictionary.
credentials = None
with open('/var/run/secrets/user_credentials/mysql_credentials') as f:
    credentials = json.load(f)

# Ensure your credentials were setup
if credentials:
    # Connect to the DB
    connection = mysql.connect(
        user=credentials.get('username'),
        password=credentials.get('password'),
        database='employees',
        host='support-mysql.dev.anaconda.com'
    )
    cursor = connection.cursor()

    # Execute the query
    cursor.execute("SELECT first_name, last_name FROM employees LIMIT 20")

    # Loop through the results
    for first_name, last_name in cursor:
        print(f'First name: {first_name}, Last name: {last_name}')

    # Close the connection
    connection.close()
 
 
import mysql.connector as mysql
import json


# Get credentials from Kubernetes. The credentials were setup as a dictionary.
credentials = None
with open('/var/run/secrets/user_credentials/mysql_credentials') as f:
    credentials = json.load(f)

# Ensure your credentials were setup
if credentials:
    # Connect to the DB
    connection = mysql.connect(
        user=credentials.get('username'),
        password=credentials.get('password'),
        database='employees',
        host='support-mysql.dev.anaconda.com'
    )
    cursor = connection.cursor()

    # Execute the query
    cursor.execute("SELECT first_name, last_name FROM employees LIMIT 20")

    # Loop through the results
    for first_name, last_name in cursor:
        print(f'First name: {first_name}, Last name: {last_name}')

    # Close the connection

 

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

 

See Storing secrets for information about adding credentials to the platform, to make them available in your projects. Any secrets you add will be available across all sessions and deployments associated with your user account.

 

[출처] https://enterprise-docs.anaconda.com/en/latest/data-science-workflows/data/mysql.html

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
46 [python][Django] [개념] Django는 Web Server가 아니라구요!! file 졸리운_곰 2023.03.11 57
45 [python][Django] [Django] Django Rest Framework에서 request 로깅하기 졸리운_곰 2023.03.11 1
44 [python][Django] Django REST Framework 졸리운_곰 2023.03.10 7
43 [python][Django] Django의 기본 개념 file 졸리운_곰 2023.03.10 3
42 Django 장고 텍스트에디터 사용하기(CKeditor) file 졸리운_곰 2020.11.22 84
41 Django Traffic Monitor + 트래픽 초과 알림 file 졸리운_곰 2020.11.22 94
40 공공 데이터 XML 크롤링을 통해 Django HTML에 띄워보기 file 졸리운_곰 2020.05.05 179
39 파이썬 장고와 워드프레스 연동의 간단한 방법 : Simple django wordpress integration with Django WordPress API library 졸리운_곰 2019.10.28 898
38 Django의 세션을 이용한 단계별 페이지 만들기 file 졸리운_곰 2019.02.02 244
37 Django 템플릿 (Template) 졸리운_곰 2019.02.02 159
36 python django 기본 file 졸리운_곰 2018.09.02 727
35 PyCharm과 함께 DJango와 RestFramework를 활용한 웹 사이트 구축하기 file 졸리운_곰 2018.05.22 192
34 Installing Python and Django on WampServer file 졸리운_곰 2018.02.18 273
33 python django 개요 다이어그램 file 졸리운_곰 2018.02.10 484
32 웹서버 중에서 Django를 선택한 이유 졸리운_곰 2017.08.22 689
31 Django App 생성 file 졸리운_곰 2017.03.06 93
30 Django - 설치 및 Hello World 웹 서비스 만들기 졸리운_곰 2017.03.05 205
29 Learning Django and AngularJS 졸리운_곰 2017.02.06 1217
28 [Django 17] Django 디버깅 file 졸리운_곰 2017.01.28 764
27 [Django 16] Django - Site Deployment 졸리운_곰 2017.01.28 212
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED