Connect to MySQL db from Jupyter notebook

前端 未结 4 1474
清歌不尽
清歌不尽 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:17

    Assuming you have MySQL installed (instructions here for macOS using HomeBrew), you need to:

    • Install pip3 install ipython-sql
    • pip3 install mysqlclient

    now you should be able to run these cells and get pretty-printed HTML output:

    # %%
    %load_ext sql
    
    # %%
    %sql mysql+mysqldb://:@localhost/
    
    # %%
    %%sql
    
    SELECT *
    FROM ;
    

    提交回复
    热议问题