• connect to mysql by odbc in linux


    原文:http://asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/installing_configuring_odbc.html

    sudo apt-get install unixODBC unixODBC-dev
    sudo apt-get install libmyodbc

    On Ubuntu, the /etc/odbcinst.ini file will be blank, so you’ll need to add the data to that configuration file. Add the following to the odbcinst.ini file:

    [MySQL]
    Description = ODBC for MySQL
    Driver = /usr/lib/odbc/libmyodbc.so
    Setup = /usr/lib/odbc/libodbcmyS.so
    FileUsage = 1

    On 64-bit systems, you will need to change the path of the libraries from /usr/lib/ to /usr/lib64/ in order to access the correct library files.

    In either case, you can use cat > /etc/odbcinst.ini to write a clean configuration file, as we’ve done in other chapters. Just use Ctrl+D to save the file once you’re done.

    Verify that the system is able to see the driver by running the following command. It should return the label name MySQL if all is well:

    # odbcinst -q -d
    [MySQL]


    Next, configure the /etc/odbc.ini file, which is used to create an identifier that Asterisk will use to reference this configuration. If at any point in the future you need to change the database to something else, you simply need to reconfigure this file, allowing Asterisk to continue to point to the same place:

    [asterisk-connector]
    Description           = MySQL connection to 'asterisk' database
    Driver                = MySQL
    Database              = asterisk
    Server                = localhost
    UserName              = asterisk
    Password              = welcome
    Port                  = 3306
    Socket                = /var/lib/mysql/mysql.sock

    On Ubuntu 10.10, the socket location is /var/run/mysqld/mysqld.sock.

    Validating the ODBC Connector

    Now, verify that you can connect to your database using the isql application. echo the select 1 statement and pipe it into isql, which will then connect using the asterisk-connector section you added to /etc/odbc.ini. You should get the following output (or at least something similar; we’re looking for a result of 1 rows fetched):

    $ echo "select 1" | isql -v asterisk-connector
    +---------------------------------------+
    | Connected!                            |
    |                                       |
    | sql-statement                         |
    | help [tablename]                      |
    | quit                                  |
    |                                       |
    +---------------------------------------+
    SQL> +------------+
    | ?column?   |
    +------------+
    | 1          |
    +------------+
    SQLRowCount returns 1
    1 rows fetched
    $ exit
  • 相关阅读:
    基于kubernetes v1.17部署dashboard:v2.0-beta8
    kubeadm快速部署Kubernetes单节点
    kafka数据可靠性深度解读
    MySql中4种批量更新的方法
    如何分析Mysql慢SQL
    企业级SSD市场接口之争:SATA会被NVMe取代吗?
    强势回归,Linux blk用实力证明自己并不弱!
    影响性能的关键部分-ceph的osd journal写
    文章汇总(包括NVMe SPDK vSAN Ceph xfs等)
    NVMe over Fabrics:概念、应用和实现
  • 原文地址:https://www.cnblogs.com/ukouryou/p/3144625.html
Copyright © 2020-2023  润新知