<jupyter_start><jupyter_text>1. mysql -> mongodb<jupyter_code>import MySQLdb, pymongo
from sqlalchemy import create_engine
db = MySQLdb.Connect(
    "172.16.31.10",
    "root",
    "dss8",
    "world",
    charset="utf8"
)
db
query = """
    select * 
    from country
"""
country_df = pd.read_sql(query, db)
country_df.tail()
client = pymongo.MongoClient("mongodb://172.16.31.10:27017")
collection = client.world.country
collection
datas = country_df.to_dict("records")
len(datas)
result = collection.insert_many(datas)
result
len(result.inserted_ids)
documents = collection.find()
df = pd.DataFrame(list(documents))
df.tail()<jupyter_output><empty_output><jupyter_text>mongodb -> mysql<jupyter_code>client
collection = client.zigbang.onsu
collection
documents = collection.find()
documents
df = pd.DataFrame(list(documents))
df.tail()
documents2 = collection.find({},{"_id":False, "_floor":True, "size":True, "deposit":True, "rent":True})
documents2
df2 = pd.DataFrame(list(documents2))
df2.tail()
engine = create_engine("mysql://root:dss8@172.16.31.10/test?charset=utf8")
engine
df2.to_sql("onsu", engine, if_exists="replace")
db = MySQLdb.connect(
    "172.16.31.10",
    "root",
    "dss8",
    "test",
    charset='utf8'
)
db
query = """
    select *
    from onsu
"""
onsu_df = pd.read_sql(query, db)
onsu_df.tail()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16494082840236687, 'fraction_numerical': 0.03994082840236687, 'mean_word_length': 5.352112676056338, 'pattern_counts': {'":': 5, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '359232', 'license': 'MIT', 'n_tokens_mistral': 554, 'n_tokens_neox': 507, 'n_words': 84, 'path': 'database/migration_review.ipynb', 'repo_name': 'Junhojuno/TIL', 'size': '1360'}