---
title: "Connect Mysql to Erlang odbc"  
description: "how to connect mysql to erlang odbc  in ubuntu 15.04 (linux)"  
author: "Sunil Singh"  
published: 2015-09-08  
updated: 2017-12-13  
canonical: https://www.mindstick.com/articles/1856/connect-mysql-to-erlang-odbc  
category: "erlang"  
tags: ["mysql", "otp", "erlang"]  
reading_time: 1 minute  

---

# Connect Mysql to Erlang odbc

First we need to [download](https://www.mindstick.com/blog/114673/download-hungry-shark-evolution-mod-apk-unlimited-money) [MySQL](https://www.mindstick.com/articles/12156/what-is-mysql) ODBC Connector from here and create dsn.\

i have created a connection_setting.hrl [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) with following [connection](https://yourviews.mindstick.com/view/83497/a-40-year-old-man-has-been-arrested-in-connection-with-the-abe-shooting) [string](https://www.mindstick.com/interview/22908/what-are-java-string-class-method)-\
-[define](https://yourviews.mindstick.com/audio/1110/lifestyles-choices-that-define-our-lives)(CONNECTIONSTRING, \
"dsn=mysql_dsn;[server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over)=localhost;[database](https://www.mindstick.com/articles/71/how-to-create-xml-file-of-database-in-c-sharp)=testdb;user=root;[password](https://www.mindstick.com/blog/118/retriving-user-password-by-using-stored-procedure-in-asp-dot-net)=[test](https://yourviews.mindstick.com/view/81706/know-about-polygraph-test-which-might-be-used-on-rhea-chakraborty);").\

```
%% @author sunil%% @doc @todo Add description to odbc_mysql.-include("connection_setting.hrl").-module(odbc_mysql).-export([mysql_connect/0,check_record_exist/2]).mysql_connect()->     application:stop(odbc),case application:start(odbc) of    ok->        {ok, Ref}=odbc:connect(?CONNECTIONSTRING,[]),        Ref;        {error,Reason}->      Reasonend.check_record_exist(Sql,Where_cond)->     Ref=mysql_connect(),    case odbc:select_count(Ref, string:concat(Sql,Where_cond)) of  {ok,Rows}->         io:format("check_record_exist success~p",[odbc:disconnect(Ref)]),         Rows;  {error,Reason}->      io:format("check_record_exist error~p~n~p",[odbc:disconnect(Ref),Reason])end.
```

---

Original Source: https://www.mindstick.com/articles/1856/connect-mysql-to-erlang-odbc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
