search
HomeOperation and MaintenanceLinux Operation and MaintenanceHow to install ODBC on Linux to connect to SQLServer database

Operating system: Centos7.2

1. Download the ODBC installation package

unixODBC-2.3.9.tar.gz

freetds-1.3.9.tar. gz

2. Installation steps

Step one: Upload two installation packages to the server

Step two: Install unixODBC, install this first, and then install freetds

Note: If the installation order is inconsistent here, the libtdsodbc.so driver file will not be generated (very important)

2.1. Install gcc on the operating system first:

yum install gcc

2.2. Installation odbc

tar -xvf unixODBC-2.3.9.tar.gz
cd unixODBC-2.3.9
./configure --prefix=/usr/local/unixODBC
make
make install

2.3. Install freetds

tar -xvf freetds-1.3.9.tar.gz
cd freetds-1.3.9
./configure --prefix=/usr/local/freetds --with-unixodbc=/usr/local/unixODBC/
make
make install

2.4. Configure freetds driver

Configuration file directory: /usr/local/freetds/etc/freetds.conf, at the end of the file Add the following content. The tds version refers to the default configuration. The default is 7.3. Just modify the host and port to the normal SQLServer address.

[SQLServer]
    host = serverip
    port = 1433
    tds version = 7.3

2.5. Test whether the configuration is correct

/usr/local /freetds/bin/tsql -S SQLServer -U username to connect to SQLServer (-S specifies the configured TDS service name, -U specifies the user name to log in to the database). A successful connection proves that the driver configuration is correct. If a connection error occurs, it is probably because the tds version setting is incorrect. You can try to modify the value and reconnect.

/usr/local/freetds/bin/tsql -S SQLServer -U sa
Password: 
locale is "zh_CN.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1>

2.6, configure unixODBC

Indicate the location and location of the database driver for unixodbc Authentication information required to connect to the database. Modify the specific values ​​in the following configuration information according to the actual situation, and configure the driver in /usr/local/unixODBC/etc/odbcinst.ini

[FreeTDS]                                         #驱动名称
Description=FreeTDS Driver
Driver=/usr/local/freetds/lib/libtdsodbc.so     #驱动位置

/usr/local/unixODBC/etc/odbc.ini

[mssql]  #DSN名称
Description=sqlserver connection
Driver=FreeTDS    #上面配置好的驱动名称
TDS_Version=7.3   #TDS驱动版本
TRACE=On    #是否输出日志信息
TraceFile=stderr  #日志信息的位置
Server=serverip  #数据库网络地址
Port=1433       #数据库端口
User=name       #登录用户名
Password=pwd     #密码
Database=db name  #连接的数据库名称

2.7. Test whether the database can be connected

/usr/local/unixODBC/bin/isql mssql name pwd
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> select * from sys.objects
+---------------------------------------------------------------------------------------------------------------------------------+------------+-------------+------------+-----------------+-----+-------------------------------------------------------------+------------------------+------------------------+--------------+-------------+--------------------+
| name                                                                                                                            | object_id  | principal_id| schema_id  | parent_object_id| type| type_desc                                                   | create_date            | modify_date            | is_ms_shipped| is_published| is_schema_published|

Note: Since we have already configured the connection database name in the configuration file, do not bring the database name when querying SQL, otherwise An error will be reported.

2.8. Shell script to connect to the database

SQL="/usr/local/unixODBC/bin/isql mssql sa 123"
i_sql=" exec dbo.bulkinsert 10,20,'dbo.stu';    "
echo $i_sql
result=`echo $i_sql|$SQL`

Method 2:

SQL="select * from Student"
EMPLOYEES=`isql mssql sa 123 <<EOF
   $SQL
   go
   EOF

Method 3:

echo "$SQL" > $TMP/sql.$$
EMPLOYEES=`isql mssql sa 123 -i $TMP/sql.$$`
rm $TMP/sql.$$

2.9. Call the command execution on the machine where SQL Server is installed Stored procedure

osql.exe -S ip -U sa -P 123 -d WAI -Q "exec dbo.bulkinsert %start%,%end%,stu

The above is the detailed content of How to install ODBC on Linux to connect to SQLServer database. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
Linux Operations: File System, Processes, and MoreLinux Operations: File System, Processes, and MoreMay 05, 2025 am 12:16 AM

The core operations of Linux file system and process management include file system management and process control. 1) File system operations include creating, deleting, copying and moving files or directories, using commands such as mkdir, rmdir, cp and mv. 2) Process management involves starting, monitoring and killing processes, using commands such as ./my_script.sh&, top and kill.

Linux Operations: Shell Scripting and AutomationLinux Operations: Shell Scripting and AutomationMay 04, 2025 am 12:15 AM

Shell scripts are powerful tools for automated execution of commands in Linux systems. 1) The shell script executes commands line by line through the interpreter to process variable substitution and conditional judgment. 2) The basic usage includes backup operations, such as using the tar command to back up the directory. 3) Advanced usage involves the use of functions and case statements to manage services. 4) Debugging skills include using set-x to enable debugging mode and set-e to exit when the command fails. 5) Performance optimization is recommended to avoid subshells, use arrays and optimization loops.

Linux Operations: Understanding the Core FunctionalityLinux Operations: Understanding the Core FunctionalityMay 03, 2025 am 12:09 AM

Linux is a Unix-based multi-user, multi-tasking operating system that emphasizes simplicity, modularity and openness. Its core functions include: file system: organized in a tree structure, supports multiple file systems such as ext4, XFS, Btrfs, and use df-T to view file system types. Process management: View the process through the ps command, manage the process using PID, involving priority settings and signal processing. Network configuration: Flexible setting of IP addresses and managing network services, and use sudoipaddradd to configure IP. These features are applied in real-life operations through basic commands and advanced script automation, improving efficiency and reducing errors.

Linux: Entering and Exiting Maintenance ModeLinux: Entering and Exiting Maintenance ModeMay 02, 2025 am 12:01 AM

The methods to enter Linux maintenance mode include: 1. Edit the GRUB configuration file, add "single" or "1" parameters and update the GRUB configuration; 2. Edit the startup parameters in the GRUB menu, add "single" or "1". Exit maintenance mode only requires restarting the system. With these steps, you can quickly enter maintenance mode when needed and exit safely, ensuring system stability and security.

Understanding Linux: The Core Components DefinedUnderstanding Linux: The Core Components DefinedMay 01, 2025 am 12:19 AM

The core components of Linux include kernel, shell, file system, process management and memory management. 1) Kernel management system resources, 2) shell provides user interaction interface, 3) file system supports multiple formats, 4) Process management is implemented through system calls such as fork, and 5) memory management uses virtual memory technology.

The Building Blocks of Linux: Key Components ExplainedThe Building Blocks of Linux: Key Components ExplainedApr 30, 2025 am 12:26 AM

The core components of the Linux system include the kernel, file system, and user space. 1. The kernel manages hardware resources and provides basic services. 2. The file system is responsible for data storage and organization. 3. Run user programs and services in the user space.

Using Maintenance Mode: Troubleshooting and Repairing LinuxUsing Maintenance Mode: Troubleshooting and Repairing LinuxApr 29, 2025 am 12:28 AM

Maintenance mode is a special operating level entered in Linux systems through single-user mode or rescue mode, and is used for system maintenance and repair. 1. Enter maintenance mode and use the command "sudosystemctlisolaterscue.target". 2. In maintenance mode, you can check and repair the file system and use the command "fsck/dev/sda1". 3. Advanced usage includes resetting the root user password, mounting the file system in read and write mode and editing the password file.

Linux Maintenance Mode: Understanding the PurposeLinux Maintenance Mode: Understanding the PurposeApr 28, 2025 am 12:01 AM

Maintenance mode is used for system maintenance and repair, allowing administrators to work in a simplified environment. 1. System Repair: Repair corrupt file system and boot loader. 2. Password reset: reset the root user password. 3. Package management: Install, update or delete software packages. By modifying the GRUB configuration or entering maintenance mode with specific keys, you can safely exit after performing maintenance tasks.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment