Skip to content

Commit 2051517

Browse files
authored
Update README.md
1 parent 2ee9817 commit 2051517

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

mysql/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ vi ~/.bashrc
121121
- Here is my sample
122122
```bash
123123
export MYSQL_HOME=/Users/txuantu/Documents/Tools/mysql
124+
export LD_LIBRARY_PATH=$MYSQL_HOME/lib
124125
export PATH=$MYSQL_HOME/bin:$PATH
125126

126127
# make alias
@@ -144,3 +145,36 @@ mysqladmin shutdown
144145
# to launch mysql console
145146
mysql -u root -p
146147
```
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+

0 commit comments

Comments
 (0)