Making MySQL ignore an error - mysql

Disclaimer: I'm trying to do something very bad and if you think I shouldn't be doing this, that's wonderful but I'm still going to do it because I'm being told explicitly to either do this or show that it can't be done.
I have a piece of code that I have absolutely 0.00% control over. This piece of code cannot be changed or edited by me in any way, I don't have the source and have no way of obtaining it. I only have control over the MySQL db itself. The code I am working with connects to the MySQL db and attempts to do an update on a table I do not want updated. The update is pointless and destructive and should not happen but the code will not proceed unless the update query goes through.
I need MySQL to lie about the update. Is there any setting or option or anything to make it so when something connects to MySQL with an account that doesn't have write access to a table tries to do an update... MySQL will just tell the client "Yeah sure no problem, update complete." and then just not do it?

Related

Where to find mysql logs regarding user changes in phpmyadmin

I want to know, is there a log that saves all the changes made by users to a database just like in git where all the commits can be viewed by each user so that if any error occur we know who did it.If there is one how to get it? or how to create one that will do it?
Problem I'm facing is that a table's data has been altered by one of the developers but there is no way to find when and who did it and also I am struggling to find all the changes that has been done to the table.
Databases typically do not provide auditing as standard. I typically implement it within my application. However, for a faster result, there are some plugins for mySQL which you could try.

Clean, low-overhead way to send an email when a mysql/mariadb table is updated?

I need to send an email when a record is added to a table.
A bunch of googling has left me with the impression that the only choices are "bad" and "really bad" and was wondering if anybody had any clean, solid, reliable suggestions.
So far I've found:
Use a mysql plugin that sends the mail. I'd rather not do this because I have a perfectly good mail server and the database wasn't designed to send mail.
Poll the table periodically from an external program, look for changes and send the mail if appropriate. This is almost OK, but I'd rather skip the dead time between the record being added and the next poll.
I had considered using SELECT ... OUTFILE, however this is really limited because it won't overwrite the output file and the only way to change the filename is by building the query with dynamic SQL, which can't be used inside a trigger.
I could write a socket listener and have Mysql open the socket and tell the mail app there are records waiting, however there doesn't seem to be a way to open a socket from mysql.
It feels like I must be missing something here.
All I want is to run an external application when a record is added.
Has anybody run into a clean, low overhead way to do this?
Modify the code that is adding the record and have it do the notifications. If you put it in a try/catch block you will know for sure whether or not the record was added successfully.
Trigger on table(s) of interest to insert into other table (email queue).
Create a scheduled process to process the other table.

Is there any event which is called whenever there is a change in the MYSQL database data?

Is there any event which detects changes in the database tables? Im trying to do a chat box. It works fine. Except that it needs to be refreshed at regular seconds of interval to get the data. But, this would eat up lot of server load. SO, i was thinking of a event which triggers any changes in the database data. Suggest me the best solution.
You could use triggers as presented in the comments. Problem with that: a trigger can only be triggered to execute an sql statemnt. So you could us a trigger, and create some kind of "activity" table with proper indexes. Problem: you still need to check this activity table! To reduce load, you should write a server component to your chat program that notifeis all clients. This way, only the server has to check to database regularly and not each client.
Without more information what language you are writing in, we can not help you more I guess.

detecting changes in a mysql database

I have someone else's code and also a db. To understand the code, I want to see that If I run a particular php process, which tables are updated in the db. Something like I start a listner and then carry out the process. After that the listner will show me a list of changes that happened in the database. Is this possible?
Note: As I understand, mysql TRIGGER does something similar but it is for a specific table and also on trigger adds rows to another table. I just want a change log sort of a thing. Thanks in advance.
You could use logging - turn it on, run the code, turn it off, then review the log file.
This article talks you through how to do this:
http://www.howtogeek.com/howto/database/monitor-all-sql-queries-in-mysql/

What is the best practice to restrict off and on times in a database?

I have two fields in my database that simply store on and off times for my application. I need to make sure that the off time is not greater than the on time. I believe that a trigger may be good but I have never written one before. Can someone either verify that a trigger is the way to go or maybe writing some PHP code to handle this would be better... Any suggestions or trigger snippets are welcome.
I'm storing the on off times which are the user's preferences. If I could get the database to return false or maybe through my PHP code, I could test for a return value and then handle it accordingly.
since mysql does not seem to allow a smooth way to abort a trigger and raise an error with an error message I would look to put this logic in the PHP code. See http://www.brokenbuild.com/blog/2006/08/15/mysql-triggers-how-do-you-abort-an-insert-update-or-delete-with-a-trigger/