So I was wondering whether I should or should not ping the mysql server (mysqli_ping) to ensure that the server is always alive before running query?
From the docs: MySQL Connector/J has the ability to execute a lightweight ping against a server, in order to validate the connection.
Queries can become slow for various reasons ranging from improper index usage to bugs in the storage engine itself. However, in most cases, queries become slow because developers or MySQL database administrators neglect to monitor them and keep an eye on their performance.
To test the connection to your database, run the telnet hostname port on your Looker server. For example, if you are running MySQL on the default port and your database name is mydb, the command would be telnet mydb 3306 . If the connection is working, you will see something similar to this: Trying 10.10.
You do not need the full MySQL server installed on the web server. Ideally it makes sense to have the client and server using the exact same version of MySQL, as they will support exactly the same features, but it's not completely necessary.
You shouldn't ping MySQL before a query for three reasons:
The best way to deal with database connections is error handling (try/catch), retries and transactions.
More on this on the MySQL performance blog: Checking for a live database connection considered harmful
In that blog post you'll see 73% of the load on that instance of MySQL was caused by applications checking if the DB was up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With