It took nearly a day to settle down and write it down for the people who need it.
Required to be installed:
Python-odbc : https://github.com/mkleehammer/pyodbc Download after install
Install PYTHON-ODBC If the report cannot find the Sql.h file error, need apt-get install g++,
This piece of code is written in C + + and requires a compiler
DJANGO-PYODBC:HTTPS://PYPI.PYTHON.ORG/PYPI/DJANGO-PYODBC download after install
unixodbc:http://www.unixodbc.org/. ODBC database source under Linux
Installation:./configure & make & make Install
or Apt-get install UnixODBC Unixodbc-dev
freetds:http://www.freetds.org/ SQL Server driver under Linux
Installation:./configure--prefix=/usr/local/freetds--with-tdsver=8.0--enable-msdblib--with-gnu-ld--enable-shared-- Enable-static
Make & make Install
Apt-get Install FreeTDS Freetds-dev TDSODBC
Configuration:
1. Configure FreeTDS
Find freetds.conf below to add:
[MySQLServer]
host = SQL Server IP
Port = 1433
TDS Version = 8.0
Client CharSet = UTF-8
Add the TSQL directory to the environment variables such as my actions: Vim/etc/profile plus a line path= $PATH:/usr/local/freetds/bin
and source/etc/profile it into effect immediately.
To test whether the FreeTDS was installed successfully:
Tsql-c look at the installation environment
TSQL-S mysqlserver-h SQL Server database ip-p 1433-u account-p password
Success will see the following information:
Locale is "en_US. UTF-8 "
Locale CharSet is "UTF-8"
Using default CharSet "UTF-8"
1>
then enter the SQL command to test it:
Use test_db
Go
SELECT * from Test;
Go
After the installation is successful, proceed to the next step.
2. Configure UNIXODBC
Find Odbc.ini Odbcinst.ini
Mine is in/etc/odbc.ini/etc/odbcinst.ini.
Vim/etc/odbcinst.ini Join
[FreeTDS]
Description = ODBC of FreeTDS for Ms-sqlserver
Driver =/usr/local/freetds/lib/libtdsodbc.so
FileUsage = 1
Vim/etc/odbc.ini Join
[ODBC connection name]
Driver = FreeTDS
ServerName = MySQLServer (FreeTDS with connection name)
Database = test_db (db name)
To test whether the Unixodbc security configuration was successful:
Isql-v ODBC connection name account password
The following message will appear when successful:
+---------------------------------------+
| connected! |
| |
| sql-statement |
| Help [TableName] |
| Quit |
| |
+---------------------------------------+
Sql>
Write a few SQL statements to test it, but this time no use test_db, because the database name has been provided
SELECT * FROM Test
I don't have to go, huh?
3. After installing PYTHON-ODBC and DJANGO-PYODBC, configure the Django setting (installation is not said, relatively simple)
' Kids ': {
' ENGINE ': ' Django_pyodbc ',
' Name ': ' Database name ', #这个不需要, but Django has a limit, there must be a name, it won't take effect, it's actually written in Odbc.ini.
' USER ': ' Account ',
' PASSWORD ': ' Password ',
' HOST ': ', #这个也不会生效, the actual effect is configured in freetds.conf
' OPTIONS ': {
' Driver ': ' FreeTDS ',
' DSN ': ' ODBC connection name ', #ODBC DSN name defined in your Odbc.ini,
}
over!
Linux (Debian) system Django with remotely connected SQL Server database