0

I'm setting up a development environment.

I'd like to check whether logging works as expected for MySQL.

How can I do so programmatically from PHP?

Inspired by this answer, I merely ran a minimal test like this:

<?php

$pdo = new \PDO(
    'mysql:host=localhost;',
    'root',
    ''
);
$result = $pdo->query( "signal sqlstate '45000' set message_text = 'Triggering error on purpose (test)';" );

?>

However, this does not trigger any error in the error log. I'd expect the error in /var/log/mysql/ (in error.log.)

I'm running Ubuntu 16.04 inside of Docker on OS X and using MariaDB.

This is a question at the crossroad between programming and sysadmin, so feel free to migrate it to AskUbuntu if you think it's more relevant there.

Community
  • 1
  • 1
Fabien Snauwaert
  • 4,995
  • 5
  • 52
  • 70
  • Are you expecting something to be written to mysqlds log file? This triggers an error for your client to handle. – Mikpa May 19 '17 at 07:15
  • @Mikpa I edited the question for clarity: I'd expect the errors in `/var/log/mysql/` (in `error.log`). Do you mean that the code above does trigger an error in the logs for you? – Fabien Snauwaert May 19 '17 at 07:23
  • signal sqlstate 45000 gives an error to the calling program, this is not normally passed to error.log. Read this http://www.mysqltutorial.org/mysql-signal-resignal/ – Mikpa May 19 '17 at 07:30

1 Answers1

1

The mysql error.log does not receive errors meant for the calling program.

Se the error.log documentation.

Mikpa
  • 1,912
  • 15
  • 20
  • 1
    “The error log contains information about mysqld startup and shutdown times, progress notes that occur during startup and shutdown, and critical errors that occur while the server is running. If mysqld notices a table that needs to be automatically checked or repaired, it writes a message to the error log.” So if I get that right, I'm better off monitoring the Apache error log for database errors, than the MySQL one. – Fabien Snauwaert May 19 '17 at 09:29