Say I have very standard mysql connection code:
$dbhost = '192.168.1.99';
$dbuser = 'dbuser';
$dbpass = 'dbuserpass';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
$dbname = 'mydb';
mysql_select_db($dbname);
This would connect from the web server to the database server (say the web server is at 192.168.1.98 or something). Typically, how long would the above code run? Currently, I'm seeing about 2 seconds. Is that slow?
One possibility is that mysql is doing a DNS lookup to find the name of the connecting server; depending on your setup, this could take a long time. There's not really much benefit to it, aside from being able to specify the users by hostname rather than IP address (e.g. user
@example.com
rather than user
@192.168.1.1
).
This can be disabled in the configuration or when starting up MySQL with the --skip-name-resolve parameter. More information is available on the MySQL site.