Port 3306 in use prevents Zend DBi MySQL daemon from starting

This article presents one of the troubleshooting steps for Zend DBi MySQL daemon start ups, found in this article:

Troubleshoot Zend DBi MySQL daemon start up failures (mysql.sock)

One reason MySQL may fail to start is if the default MySQL port 3306 is in use.   One way to check if port 3306 is in use is to use the netstat command.  A limitation of netstat is that it can only show jobs using a port, but not tasks.  If port 3306 is in use, we will want to know which job or task is using it.  Navigator can show both jobs and tasks, so this is a better way to check the port.

In Navigator, go to Network -> TCP/IP Configuration -> IPv4 -> Connections. Click the local port column title to sort by local port.  Look for local port 3306 on the list. Right click the line that shows local port 3306. The menu will show Stop, Jobs, Tasks, and Properties. Use the Tasks menu option to display any tasks using the port. Use the Jobs menu option to display any jobs using the port.

In the following example animation, Zend Server 5 has been set up to use port 3306.  This is not something we would normally do.  I just did it to show what it looks like when some job or task uses port 3306:

navport

If port 3306 does not appear on the list of local ports, this is probably not the problem. Please return to the troubleshooter to try another step.

If port 3306 does appear on the list, take a look at the job or task using the port.  Port 3306 is usually reserved for MySQL, so other products using this port were likely set up custom to use this port.  It may be possible to change the other product to use some other port. This is the preferable solution.  Unfortunately, it is often not the most practical solution. The other option is to change the port used by the Zend DBi MySQL daemon.

To change the MySQL daemon port, you will first need to locate an unused port.  The following article can help with this task:

Find an Available Port

Now you need to update the start up shell script, /usr/local/mysql/bin/mysql.sh .

IMPORTANT:  

Before editing this file, or any configuration file, it is always important to make a back up copy.

We do not recommend using the 5250 EDTF command to edit this file, because the first line is longer than can be displayed on a 5250 terminal emulator. The EDTF command can truncate characters at the end of the displayed part of the line, causing them to be lost from the middle of the complete line, if insert is used. If WRKLNK is used to display the file, and then option 2 is used to edit, this is the same as using the EDTF command, so this is also not recommended.

We do not recommend using Notepad or other basic Windows editors to edit this file. The FastCGI configuration uses the Unix/Linux standard of using only the new line character (\n) at the end of each line, while Windows uses a carriage return and new line at the end of each line (\r\n). FastCGI expects the ‘\n’, but Notepad will insert the ‘\r\n’ at the end of each line. As a result, your configuration file will appear to be correct when you view it in the editor, but FastCGI will not start.

Editors that we know of that properly handle the end of line include Zend Studio and Notepad ++ .  In Studio, right click the file name and choose Open With -> Text Editor.  Otherwise, the file may open for editing in a Notepad window, and the end of line will be corrupted when saving the file.

The start up shell script used by Zend DBi is:

/usr/local/mysql/bin/mysql.sh

Please make a back up copy of this file before editing.

In the script, find the mysqld command. It will look something like this:

$BASEDIR/bin/mysqld --defaults-file=${DEFS_FILE} --basedir=${BASEDIR} --datadir=${DATADIR} \
 --port=3306 --user=${USER} --socket=${SOCKET_PATH} \
 --pid-file=${PID_PATH} --tmpdir=${TEMP} 2> /dev/null 1> /dev/null &

In the above example, note the port=3306. Change the port number to the new port.  Don’t change anything else.  In the following example we changed the port to 3307:

$BASEDIR/bin/mysqld --defaults-file=${DEFS_FILE} --basedir=${BASEDIR} --datadir=${DATADIR} \
 --port=3307 --user=${USER} --socket=${SOCKET_PATH} \
 --pid-file=${PID_PATH} --tmpdir=${TEMP} 2> /dev/null 1> /dev/null &

Save your changes. The next time the Zend DBi MySQL daemon is started, it will use the new port.  This should allow the daemon to start successfully.

Things to remember when you change the MySQL port:

When you deploy phpMyAdmin, you will need to know the port that is used for MySQL.

If you are using a third party PHP application that uses MySQL, please check with the vendor to learn how to update the MySQL port.

If you are writing or updating your own application, please remember to specifiy the report in the connection. In the following example, they specify port 3307:

// we connect to example.com and port 3307
$link = mysql_connect(‘example.com:3307’, ‘mysql_user’, ‘mysql_password’);

This example is from Example #2 on the mysql_connect() function documentation page:

http://www.php.net/manual/en/function.mysql-connect.php

Bookmark the permalink.

Leave a Reply