| 1 | = MySql HowTo log SQL errors |
| 2 | |
| 3 | Tags: [[MySql]] [[HowTo]] |
| 4 | |
| 5 | == Introduction |
| 6 | |
| 7 | The MySQL error log only contains errors experienced by MySQL and not queries that cause an error. And because PHP tries to make development as hard as possible, it quite often hides what errors are being returned from MySQL, either with a WSOD or with the helpful 'Unknown Error' message. Therefore, the only way to see what error is being produced is to use mysql-proxy to sit between the client and MySQL and create LUA script to display the error messages. |
| 8 | |
| 9 | == Procedure |
| 10 | |
| 11 | === Install MySQL-Proxy |
| 12 | |
| 13 | 1. Download the latest tar file from [[https://downloads.mysql.com/archives/proxy/]] |
| 14 | 2. Unzip the file using the command `sudo tar zxf mysql-proxy-0.8.5-linux-debian6.0-{version}.tar.gz -C /usr/local` |
| 15 | |
| 16 | === Create the lua script to log the error and run. |
| 17 | |
| 18 | 1. Copy the script from here: [[http://www.chriscalender.com/capturing-erroneous-queries-with-mysql-proxy/]] |
| 19 | 2. Run the mysql proxy command. For example: |
| 20 | |
| 21 | {{{ |
| 22 | /usr/local/mysql-proxy-0.8.5-linux-debian6.0-x86-64bit/bin/mysql-proxy --proxy-backend-addresses=127.0.0.1:3306 --proxy-address=0.0.0.0:4045 --proxy-lua-script=/home/richard/mysql_proxy_log_errors.lua |
| 23 | }}} |
| 24 | |
| 25 | 3. Change the connection string of the clinet application to use the new port (4045). |
| 26 | |
| 27 | [[BackLinks]] |