Connect to MySQL db from Jupyter notebook

前端 未结 4 1482
清歌不尽
清歌不尽 2021-01-02 21:31

I am using Jupyter Notebooks to learn Python. I would like to connect to a MySQL db hosted locally hosted through MAMP. How would I approach this?

4条回答
  •  情歌与酒
    2021-01-02 22:23

    Yes, you can. You can use the MySQL Connector library. Simply install it using pip, and then you can use it to interact with your database. See the sample code below:

    import mysql.connector
    
    db = mysql.connector.connect(
       host="localhost",
       user="mamp",
       passwd=""
    )
    
    print(db)
    

提交回复
热议问题