Python Connection Database

Source: Internet
Author: User

2017.12.14
Because the SQLAlchemy does not support MongoDB database now, SQL Server is not very good, now mainly with MySQL database.

# http://docs.sqlalchemy.org/en/latest/
# http://docs.sqlalchemy.org/en/latest/core/engines.html Connect each Database interface document
# SQLAlchemy Docs and Tutoria
Import Pandas as PD
Import NumPy as NP
From pandas import Series,dataframe
From SQLAlchemy import Create_engine
#连接格式
#dialect +driver://username:[email protected]:p ort/database
#一, connect MySQL database pip install mysqlclient #MySQLdb已停止更新
#如果不安装mysqlclient, Error: Modulenotfounderror:no module named ' MySQLdb '
#con =create_engine ("Mysql+mysqldb://root:[email protected]/test") #自己的mysql数据库
# con=create_engine ("Mysql+mysqldb://scott:[email protected]/abc")
# con=create_engine ("Mysql://scott:[email protected]/abc") #安装mysqlclient后可以不加driver
#二, connect to MongoDB database
#con =create_engine ()
#三, connecting to a SQL Server database
#不要安装pymssql库, update is not timely, PYODBC for Anaconda built-in library, without installation is available
#写入数据库时候有问题, error, but seems to be connected successfully
#con =create_engine ("Mssql+pyodbc://scott:[email protected]/yqtest")
#四, connect SQLite database, not easy to visualize, now do not use
#注意是3个 "///", not two
#con =create_engine (' Sqlite:///mydata.sqlite ')
#五, PostgreSQL database
#con = Create_engine (' Postgresql://scott:[email protected]/mydatabase ')
DATA=PD. DataFrame (Np.arange (+) reshape (bis)) #,columns=list (' Xyzm ') #index =[' A ', ' B ', ' C ', ' d ']
#data =PD. DataFrame (Np.arange) reshape (bis), index=[' A ', ' B ', ' C ', ' d '],columns=list (' Xyzm '))
Data.to_sql (name= ' Yangqiete ', Con=con)

Python Connection Database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.