I need to use the database recently. I am familiar with sql server and use this, but accessing it with python is a bit tricky. Record it.
First install pymssql
pip install -i https://pypi.doubanio.com/simple/ pymssql
Importing and using it directly is ok, mainly because of the connection string. Most of what is given online are as follows:
ms = MSSQL(host="localhost",user="sa",pwd="123456",db="PythonWeiboStatistics")
MSSQL is a class, and it is easy to search for pymssql on the Internet and not post it. The first three parameters need to be explained here. I also changed the password of sa in the sql server. The host tried '.' 'localhost' '127.0.01' 'IP' and kept reporting an error, and the connection adapter was wrong. Finally, I looked at the attribute options in my sql server, and changed these three items to the corresponding values in the attribute. The password is the power-on password of the machine, as shown below.