Mysql UPDATE is delayed a few seconds (Perl dbi) - mysql

I have encountered a strange behavior in mysql, using dbi in Perl.
At the end of a perl program, I issue a mysql UPDATE command to a table. The command is executed using $dbh->execute(); and autocommit is turned on.
After the execute, the program issues $dbh->disconnect(); and exits.
The perl program runs as part of a script. Immediately when the perl program has stopped, another script executes. This script looks as the table that was updated, and here is when things become confusing to me.
Sometimes script 2 reads the old data in the table. Sometimes it sees what was just updated. I cannot understand how the initial perl program can do the $dbh->execute(); and yet it seems that the mysql table is updated several seconds later.
Any insight would be helpful! Cheers in advance.

Turns out the problem was never with either mysql or Perl.
The problem was that the two scripts were running as a script called by a crontab job. Unless specified, crontab did not run using the bash shell.
See
https://askubuntu.com/questions/117978/script-doesnt-run-via-crontab-but-works-fine-standalone
for more information.

Related

No matter what I query, MySQLWorkbench gives me the same response

While I am just learning MySQL and MySQLWorkbench, and have perhaps have done something boneheaded, I cannot find a reference to this.
Suddenly, no matter what line of code or what query I run, it outputs the same response even if I query for tables disconnected to the response. The database tests connected. I have run the use command. I have tried to google hack this and found nothing close to my situation. It was running just fine. I did not change the database. I was just running some very basic SELECT queries.
Any ideas?
Did you check your installation ?

Run bash script after update table in mariadb [duplicate]

I'm currently writing my Main Assignment on my last semester at my study (IT-Engineering with Networking) and currently working with MySQL.
My question is: Is it possible to execute a Shell script/Command from within a MySQL Trigger/Procedure? Or can it be done from a CASE statement?
I've been searching around the internet and read that it's inadvisable to do it.
But I need a script to check a table in a database for alerts and then warn people if there is any.
If there is anyway else this could be done, then I'm open for ideas.
Any input will be appreciated :)
You can read this blog for triggering a shell script from MySQL:
https://patternbuffer.wordpress.com/2012/09/14/triggering-shell-script-from-mysql/. To summarize, two options are presented:
Polling. To improve performance, a trigger could record the change in another table which you poll instead.
MySQL UDF. Write your own plugin, and beware of security implications!
I think for your requirement just write a python/php/perl script which will connect your MySQL DB and query the alert table for any alert and accordingly show warning message on the screen or send email/sms warning.

Execute Shell script/command from MySQL Trigger/Stored Procedure

I'm currently writing my Main Assignment on my last semester at my study (IT-Engineering with Networking) and currently working with MySQL.
My question is: Is it possible to execute a Shell script/Command from within a MySQL Trigger/Procedure? Or can it be done from a CASE statement?
I've been searching around the internet and read that it's inadvisable to do it.
But I need a script to check a table in a database for alerts and then warn people if there is any.
If there is anyway else this could be done, then I'm open for ideas.
Any input will be appreciated :)
You can read this blog for triggering a shell script from MySQL:
https://patternbuffer.wordpress.com/2012/09/14/triggering-shell-script-from-mysql/. To summarize, two options are presented:
Polling. To improve performance, a trigger could record the change in another table which you poll instead.
MySQL UDF. Write your own plugin, and beware of security implications!
I think for your requirement just write a python/php/perl script which will connect your MySQL DB and query the alert table for any alert and accordingly show warning message on the screen or send email/sms warning.

Why is the init file not populating Memory Tables in MySQL?

For optimizing system performance, we are storing a few static tables on RAM (copies of which does exist on the hard-drive as well -- on the MyISAM). Now, as we all know, when the server re-starts all data on RAM gets deleted. Hence to avoid that we created an init file that has 4 SQL statements.
Please note that each SQL statement exists on a separate line, ended with a semi-colon (;) and there are no comments anywhere --- so from my limited knowledge, I believe that I have avoided making some basic mistakes. However, when I re-start MySQL manually from the command line to test it, I see that the memory tables are empty. There are no issues with the initfile itself, because when I execute the initfile manually from the command line, the data gets populated without any issues.
Any help in terms of resolving this will be much appreciated!
Thanks!
Udayan
Something is not right here.
Just to check, I tried restarting my local mysql server using /etc/init.d/mysql restart. And, it started up as running by the mysql user (not root).
So, we will need the following to try to figure this out because I am just about positive that the problem is either that the file has the wrong permissions or it is in a location that the user running mysqld does not have access to.
What version of Linux are you running?
What is the version of mySQL that you have installed?
Is 'init-file=' in the right section of my.cnf?
What is the output of 'ps -ef | grep mysqld'?
What is the output of 'ls -lrt /tmp/initfile.sql'?
What did you mean by 'There are no issues with the initfile itself,
because when I execute the initfile manually from the command line,
the data gets populated without any issues.'?
I cannot help but think that it is a permissions problem. So the fourth and fifth answers are the ones that I am most interested in.
You should add all of these answers to your question - so that people have everything they need to help you solve your problem.
Appreciate all your suggestions but I have figured out what the issues were.
In the SQL file I needed to mention which database that init-file should populate.
I had trailing semi-colons in the SQL statements -- apparently that is not a good idea.
Once I made these two small changes, everything started working fine.
Again, thanks for the pointers!
Udayan

HDBC-mysql "command out of sync"

I'm writing a web app using Snap 0.6 and the Snaplet-hdbc infrastructure. In the backend, I'm using HDBC-mysql to connect to MySQL. But when running the app, it gets a "Command out of sync, you can't run this command now" error from MySQL. I'am using withTransaction' for each query. After some googling, it seems that MySQL doesn't support multiple query. But how to avoid it using HDBC?
After some investigation, I found the solution. Don't use SELECT statement in withTransaction or with commit. And don't use query' for SELECT. In my opinion, HDBC-mysql is using the mysqlclient library, so you can't issue a new query when the data of last query is still unused or freed. Due to the laziness of haskell, if you run a SELECT in withTransaction, the data is unused until your code need it, so when the withTransaction function calls commit, it will result in the "Command out of sync" error. For query', maybe it returns the number of rows selected, but the data selected out is buffered by the mysqlclient library, so it's the problem.