I'm looking for a solution similar to the inotify method of watching files for changes. I'm aware that I could watch the binlog file of the mysql database and run queries to pick out the new results but that seems very inefficient and inelegant; as does simply doing masses of queries in a loop waiting for new results.
When you connect to a MySQL database, you need the following information: First, you need to tell DBI where to find the MySQL database server. This is called the data source name or DSN. The data source name specifies the driver to use and the database to connect. Perl requires the data source name to begin with dbi: and the name of the driver.
When you connect to a MySQL database, you need the following information: First, you need to tell DBI where to find the MySQL database server. This is called the data source name or DSN. The data source name specifies the driver to use and the database to connect.
Perl DBI detects errors when they occur and calls either warn () or die () function with an appropriate error message. The PrintError attribute instructs DBI to call the warn () function that shows the errors to the output. The RaiseError attribute tells DBI to call the die () function upon error and to abort the script immediately.
1 First, use the use DBI; statement at the top of the script. 2 Next, define some variables to hold the data source name, username, and password. 3 Then, define a hash that contains the connection’s attributes. 4 After that, pass the corresponding arguments to the connect () method to create a connection to the perlmysqdb database. More items...
If you add a TRIGGER to the table(s) you're interested in, you can use that to alert the watching application. You could do that in a number of ways:
As far as MyISAM tables go you can watch information_schema.TABLES.UPDATE_TIME
. That would save you from polling all tables you're interested in. For InnoDB, watching binlog is the best I can think of.
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