<jupyter_start><jupyter_text>Python and MySQL First import the python module containing the API<jupyter_code>import pymysql<jupyter_output><empty_output><jupyter_text>Set up a connection and create a cursor object<jupyter_code>db = pymysql.connect("localhost","root","None" ,database="schooldb")
cursor = db.cursor()<jupyter_output><empty_output><jupyter_text>Execute a query and get the results<jupyter_code>cursor.execute('show tables;')
cursor.fetchall()
               
query = """
SELECT course.name FROM student 
INNER JOIN enrolls_in ON student.ssn = enrolls_in.ssn 
INNER JOIN course ON course.number = enrolls_in.class
WHERE f_name = "JOHN";
"""
cursor.execute(query)
cursor.fetchall()
# 向数据库插入数据
insert = 'INSERT INTO Student VALUES ("", "")' 
cursor.execute(insert)
cursor.fetchall()
# 同步到数据库
db.commit()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11834319526627218, 'fraction_numerical': 0.0, 'mean_word_length': 6.6909090909090905, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '3239', 'license': 'MIT', 'n_tokens_mistral': 303, 'n_tokens_neox': 294, 'n_words': 64, 'path': 'BAMM.101x/sql_and_python.ipynb', 'repo_name': 'KECB/learn', 'size': '845'}