File tree 1 file changed +34
-0
lines changed
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,7 @@ vi ~/.bashrc
121
121
- Here is my sample
122
122
``` bash
123
123
export MYSQL_HOME=/Users/txuantu/Documents/Tools/mysql
124
+ export LD_LIBRARY_PATH=$MYSQL_HOME /lib
124
125
export PATH=$MYSQL_HOME /bin:$PATH
125
126
126
127
# make alias
@@ -144,3 +145,36 @@ mysqladmin shutdown
144
145
# to launch mysql console
145
146
mysql -u root -p
146
147
```
148
+
149
+ #### 3.7. Test mysql-python connection
150
+ - Requirements
151
+ ``` bash
152
+ pip install mysql-python
153
+ pip install mysqlclient
154
+ pip install sqlalchemy
155
+ ```
156
+
157
+ - Simple Python
158
+ ``` python
159
+ from sqlalchemy import create_engine
160
+
161
+ eng = create_engine(' mysql://<username>:<password>@localhost:3306/<databasename>?unix_socket=/path/to/thesock' )
162
+ with eng.connect() as con:
163
+
164
+ rs = con.execute(' SELECT 6' )
165
+
166
+ data = rs.fetchone()[0 ]
167
+
168
+ print " Data: %s " % data
169
+ ```
170
+ - Python pandas
171
+ ``` python
172
+ from pandas.io import sql
173
+ from sqlalchemy import create_engine
174
+
175
+ eng = create_engine(' mysql://<username>:<password>@localhost:3306/<databasename>?unix_socket=/path/to/thesock' )
176
+ cnx = eng.raw_connection()
177
+ xx = sql.read_frame(" SELECT * FROM <tablename>" , cnx)
178
+ cnx.close()
179
+ ```
180
+
You can’t perform that action at this time.
0 commit comments