安装odbcconnector
apt install unixodbc php7.2-odbc
php的odbc也要打开设置好
mysql-connector安装
下载mysql-connector
解压缩
用管理员权限
shell> cp bin/* /usr/local/bin
shell> cp lib/* /usr/local/lib
根据需要选择unicode或者ansi
// Registers the Unicode driver:
shell> myodbc-installer -a -d -n “MySQL ODBC 8.0 Driver” -t “Driver=/usr/local/lib/libmyodbc8w.so”
// Registers the ANSI driver
shell> myodbc-installer -a -d -n “MySQL ODBC 8.0” -t “Driver=/usr/local/lib/libmyodbc8a.so”
验证一下shell> myodbc-installer -d -l
/etc/odbc.ini
[Database-connector]
Description = MYSQL connection to ‘Database’ database
Driver = MySQL ODBC 8.0 Driver
Database = Datebase
Server = localhost
UserName = username
Password = usenamepasswords
Port = 3306
Charset =utf8
/etc/odbcinst.ini
[MySQL]
Description=ODBC for MySQL
Driver=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
Setup=/usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
FileUsage=1
[MySQL ODBC 8.0 Driver]
Driver=/usr/local/lib/libmyodbc8w.so
UsageCount=1
isql命令
- unixODBC - isql *
- Syntax *
-
*
-
isql DSN [UID [PWD]] [options] *
-
*
- Options *
-
*
- -b batch.(no prompting etc) *
- -dx delimit columns with x *
- -x0xXX delimit columns with XX, where *
-
x is in hex, ie 0x09 is tab *
- -w wrap results in an HTML table *
- -c column names on first row. *
-
(only used when -d) *
- -mn limit column display width to n *
- -v verbose. *
- -lx set locale to x *
- -q wrap char fields in dquotes *
- -3 Use ODBC 3 calls *
- -n Use new line processing *
- -e Use SQLExecDirect not Prepare *
- -k Use SQLDriverConnect *
- -L Length of col display (def:300) *
- –version version *
-
*
- Commands *
-
*
- help - list tables *
- help table - list columns in table *
- help help - list all help options *
-
*
- Examples *
-
*
-
isql WebDB MyID MyPWD -w < My.sql *
-
*
-
Each line in My.sql must contain *
-
exactly 1 SQL command except for the *
-
last line which must be blank (unless *
-
-n option specified). *
-
*
- Please visit; *
-
*
-
http://www.unixodbc.org *
-
nick@lurcher.org *
-
pharvey@codebydesign.com *
用isql测试
isql Database-connector username -v
±--------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
±--------------------------------------+
SQL>
如果用isql DSN -v不加用户的话,会报错,默认是你当前用户
[S1000][unixODBC][MySQL][ODBC 8.0(w) Driver]Access denied for user ‘你的当前用户名’@‘localhost’ (using password: YES)
[ISQL]ERROR: Could not SQLConnect
不知道为什么不认odbc.ini配置里面的用户名跟密码,我现在还没搞懂。