In most cases, you’ll want to display system variables for your MySQL server. This is because MySQL is a powerful database and it can be difficult to keep track of all the information that affects it. Here are some tips on how to do this:
- In the mysql_secure_installation() function, set the SHOW VARIABLE option to show all system variables. This will help you see what affects your MySQL server and how they are related.
- In the mysql_query() function, set the SHOW VARIABLE option to show specific system variables. This will help you see which values are affected by a particular query or statement.
- In the mysql_result() function, set the SHOW VARIABLE option to show specific system variables only if they have a value. Otherwise, they will be hidden from view in the result set.
If you are running a MySQL database server, you might be wondering how to see the current settings for the database. In MySQL they are called variables, and it’s very easy to see the current values.
The simplest way is to just use this command from the MySQL prompt, which will show every current configuration setting.
If you want to see only a specific variable, you can use this command. Obviously you’d want to replace the max_connect_errors in that command with the variable that you’re looking for.
If you want to change the current state of a variable, you can do so easily with a command similar to this one:
If you’re reading this post you might be wondering why we bothered to write a post about this subject, considering there’s a user manual for MySQL. Earlier tonight (as of the writing of this post), our web server had a problem connecting to the database. When looking through the logs, it became clear that the database server had blocked the web server from connecting because of some connection errors. The solution was even easier to figure out.
Turns out, our hosting provider is in the process of upgrading their switch firmware because of some issues — which are causing some connection errors. Because the default MySQL setting for maximum connection errors is a silly limit of 10, our database server started rejecting incoming connections. Thankfully we were able to fix it quickly with a FLUSH HOSTS command on the database server, but it was time to increase the variable. So… this post is just so we won’t forget what we did next time.