26 | | Debian Linux: shared module |
27 | | --------------------------- |
28 | | 1. Install |
29 | | # apt-get install python-mysqldb |
30 | | |
31 | | [ 2003/07: if you have multiple Python versions installed you may want to do |
32 | | # apt-get install python2.2-mysqldb |
33 | | or |
34 | | # apt-get install python2.3-mysqldb |
35 | | ] |
| 17 | === Debian Linux: shared module === |
| 18 | 1. Install |
| 19 | {{{ |
| 20 | # apt-get install python-mysqldb |
| 21 | }}} |
| 22 | If you have multiple Python versions installed you may want to do |
| 23 | {{{ |
| 24 | # apt-get install python2.2-mysqldb |
| 25 | or |
| 26 | # apt-get install python2.3-mysqldb |
| 27 | }}} |
45 | | Other Unix/Linux: shared module |
46 | | ------------------------------- |
47 | | 1. Download MySQL-python |
48 | | $ wget http://easynews.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-0.9.2.tar.gz |
| 58 | === Unix/Linux: compiled statically into Python === |
| 59 | 1. Download MySQL-python |
| 60 | {{{ |
| 61 | $ wget http://easynews.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-0.9.2.tar.gz |
| 62 | }}} |
| 63 | 1. Unpack |
| 64 | {{{ |
| 65 | $ gunzip -c MySQL-python-0.9.2.tar.gz | tar xf - |
| 66 | }}} |
| 67 | 1. Download Python |
| 68 | {{{ |
| 69 | $ wget http://python.org/ftp/python/2.3/Python-2.3.tgz |
| 70 | }}} |
| 71 | 1. Unpack |
| 72 | {{{ |
| 73 | $ gunzip -c Python-2.3.tgz | tar xf - |
| 74 | }}} |
| 75 | 1. Copy MySQL files |
| 76 | {{{ |
| 77 | $ cp MySQL-python-0.9.2/{*.c,*.h} Python-2.3/Modules/ |
| 78 | $ cp MySQL-python-0.9.2/_mysql_exceptions.py Python-2.3/Lib/ |
| 79 | $ cp -r MySQL-python-0.9.2/MySQLdb Python-2.3/Lib/ |
| 80 | }}} |
| 81 | 1. Enter the MySQL module in the Python extension setup file. |
| 82 | {{{ |
| 83 | $ cd Python-2.3/ |
| 84 | $ perl -wpi.bak -e "s,^_sre _sre.c,_mysql _mysql.c `mysql_config --cflags` `mysql_config --libs`\n$&," Modules/Setup |
| 85 | (This adds the line '_mysql _msql.c [flags]' to Modules/Setup) |
50 | | 2. Unpack |
51 | | $ gunzip -c MySQL-python-0.9.2.tar.gz | tar xf - |
| 87 | $ perl -wpi.bak -e 's,^LIBSUBDIRS=\s+,$&MySQLdb ,' Makefile.pre.in |
| 88 | (This adds MySQLdb to the list of libraries to install) |
| 89 | }}} |
| 90 | 1. Configure python |
| 91 | {{{ |
| 92 | $ cd Python-2.3/ |
| 93 | $ ./configure --prefix=/usr/local |
| 94 | or whatever path you want instead of /usr/local] |
| 95 | }}} |
| 96 | 1. Build |
| 97 | {{{ |
| 98 | $ make |
| 99 | }}} |
| 100 | Troubleshooting: |
| 101 | If you get undefined symbols or other compile errors in `_mysql.c` you probably didn't add the correct include directory for mysql. If you get unresolved symbols or other link errors involving `_mysql.o` or `libmysql.a` you probably didn't add the correct libraries. |
| 102 | You may want to check Python and MySQLdb are working before installing by running ./python; see below for instructions. |
| 103 | 1. Install |
| 104 | {{{ |
| 105 | $ cd ../Python-2.3/ |
| 106 | # make install |
| 107 | }}} |
53 | | 3. Build |
54 | | $ cd MySQL-python-0.9.2 |
55 | | $ python setup.py build |
56 | | |
57 | | 4. Install |
58 | | # python setup.py install |
59 | | |
60 | | Unix/Linux: compiled statically into Python |
61 | | ------------------------------------------- |
62 | | 1. Download MySQL-python |
63 | | $ wget http://easynews.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-0.9.2.tar.gz |
64 | | |
65 | | 2. Unpack |
66 | | $ gunzip -c MySQL-python-0.9.2.tar.gz | tar xf - |
67 | | |
68 | | 3. Download Python |
69 | | $ wget http://python.org/ftp/python/2.3/Python-2.3.tgz |
70 | | |
71 | | 4. Unpack |
72 | | $ gunzip -c Python-2.3.tgz | tar xf - |
73 | | |
74 | | 5. Copy MySQL files |
75 | | $ cp MySQL-python-0.9.2/{*.c,*.h} Python-2.3/Modules/ |
76 | | $ cp MySQL-python-0.9.2/_mysql_exceptions.py Python-2.3/Lib/ |
77 | | $ cp -r MySQL-python-0.9.2/MySQLdb Python-2.3/Lib/ |
78 | | |
79 | | 8. Enter the MySQL module in the Python extension setup file. |
80 | | $ cd Python-2.3/ |
81 | | $ perl -wpi.bak -e "s,^_sre _sre.c,_mysql _mysql.c `mysql_config --cflags` `mysql_config --libs`\n$&," Modules/Setup |
82 | | (This adds the line '_mysql _msql.c [flags]' to Modules/Setup) |
83 | | |
84 | | $ perl -wpi.bak -e 's,^LIBSUBDIRS=\s+,$&MySQLdb ,' Makefile.pre.in |
85 | | (This adds MySQLdb to the list of libraries to install) |
86 | | |
87 | | 7. Configure python |
88 | | $ cd Python-2.3/ |
89 | | $ ./configure --prefix=/usr/local |
90 | | [or whatever path you want instead of /usr/local] |
91 | | |
92 | | 8. Build |
93 | | $ make |
94 | | |
95 | | Troubleshooting: |
96 | | If you get undefined symbols or other compile errors in |
97 | | _mysql.c you probably didn't add the correct include |
98 | | directory for mysql. If you get unresolved symbols or other |
99 | | link errors involving _mysql.o or libmysql.a you probably |
100 | | didn't add the correct libraries. |
101 | | |
102 | | You may want to check Python and MySQLdb are working before installing |
103 | | by running ./python; see below for instructions. |
104 | | |
105 | | 9. Install |
106 | | $ cd ../Python-2.3/ |
107 | | # make install |
108 | | |
109 | | Windows: pre-built binary |
110 | | ------------------------- |
111 | | There is a built python executable available at the URL listed. |
112 | | |
113 | | Does it work? |
114 | | ============= |
115 | | You can check if your Python and/or MySQLdb was compiled and installed |
116 | | correctly like this: |
117 | | |
118 | | $ python |
119 | | >>> import MySQLdb |
120 | | >>> MySQLdb.version_info |
121 | | >>> MySQLdb.connect(db='databasename', user='username') |
| 109 | == Does it work? == |
| 110 | You can check if your Python and/or MySQLdb was compiled and installed correctly like this: |
| 111 | {{{ |
| 112 | $ python |
| 113 | >>> import MySQLdb |
| 114 | >>> MySQLdb.version_info |
| 115 | >>> MySQLdb.connect(db='databasename', user='username') |