Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ffdf4ee

Browse files
Create README.md
1 parent 41ed4b1 commit ffdf4ee

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

‎README.md‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## How to connect to Mysql using C++ in Mac Osx
2+
3+
There are 2 ways of doing that first user mysql.h file or using mysql connector
4+
5+
### Using Mysql.h
6+
You can check demo1.cpp file which is using mysql.h
7+
STEPS ARE:
8+
9+
By Default g++ uses clang compiler which comes with Xcode which is not a genuine compiler so you need to reinstall to have genuine compiler for g++
10+
You can check version with g++ --version
11+
1. Install macports using brew
12+
2. sudo port selfupdate
13+
3. sudo port install gcc46
14+
4. sudo port select --set gcc mp-gcc46
15+
5. Now check again gcc --version it should Say (gcc (MacPorts gcc46 4.6.4_11) 4.6.4) ...
16+
17+
18+
Installing and running mysql
19+
1. brew install mysql
20+
2. g++ -o demo1 -I/usr/local/include -I/usr/local/include/mysql -W -lmysqlclient -L/usr/local/lib demo1.cpp
21+
3. Run ./demo1
22+
23+
### Using Mysql Connector CPP
24+
STEP 1 - Connector
25+
1. Download Mysql C++ Connector for Mac OS from here https://dev.mysql.com/downloads/connector/cpp/
26+
1. Extract cppconn direcotry and mysql_connection.h, mysql_driver.h, mysql_error.h file to the root direcotry of your application
27+
28+
STEP 2 - CREATE DYLIB file from cpp connector using the same compiler we are using to compile our code
29+
git clone https://github.com/mysql/mysql-connector-cpp .
30+
git checkout 1.1
31+
git tag
32+
git checkout tags/1.1.9
33+
which g++
34+
which gcc
35+
cmake -DCMAKE_C_COMPILER=/opt/local/bin/gcc -DCMAKE_CXX_COMPILER=/opt/local/bin/g++ .
36+
make
37+
make install
38+
You should find dylib files in driver director and copy those files to the same directory where your code exists
39+
40+
STEP 3 - RUNNING CODE
41+
g++ -o demo -I/usr/local/include -I/Volumes/D/www/c++ -L. -lmysqlcppconn demo.cpp
42+
./demo

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /