HiveSQL for Python developers

Use the following code to connect to HiveSQL using Python:

import pypyodbc
connection = pypyodbc.connect('Driver={ODBC Driver 13 for SQL Server};'
                              'Server=vip.hivesql.io;'
                              'Database=DBHive;'
                              'uid=[your_hivesql_account];'
                              'pwd=[your_hivesql_password]')
cursor = connection.cursor() 
SQLCommand = ("YOUR SQL QUERY”)
cursor.execute(SQLCommand)
# do whatever you want with the retrieved data
connection.close()

Remember you need to have ODBC drivers installed on your computer.

How to install the Microsoft ODBC Driver for SQL Server on Linux and macOS

On Debian 9

sudo curl https://ift.tt/2OlWDWn > /etc/apt/sources.list.d/mssql-release.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql17

Optional for bcp and sqlcmd

sudo ACCEPT_EULA=Y apt-get install mssql-tools
echo ‘export PATH=”$PATH:/opt/mssql-tools/bin”‘ >> ~/.bash_profile
echo ‘export PATH=”$PATH:/opt/mssql-tools/bin”‘ >> ~/.bashrc
source ~/.bashrc

Optional for unixODBC development headers

sudo apt-get install unixodbc-dev

For more details on how to install Microsoft SQL ODBC drivers, you can read this post published by @geekgirl

Last updated