Today I failed to delete a record from a table in my database. I tried on both of my database management applications in MAC: MySQL Pro and MySQLWorkbench, but each of them created different error!
MySQL Pro
MySQLWorkbench
For both MySQL Pro and MySQLWorkbench, I am sure that I am log in using primary instance's link (not replica's) with user having DELETE privilege on this database.
Why the same database responds 2 different errors?
What settings should I look at in order to fix this?
I have checked all foreign keys referring to the record ID which I currently want to delete. It looks good.
Then I delete all records in the "child" tables referring to the ID of the record; and go back to delete the record -> it works!
I remember I had once changed a foreign keys from CASCADE for ON DELETE/UPDATE to NULL for ON DELETE/UPDATE, then I rolled back (CASCADE for ON DELETE/UPDATE). Not sure if that is the root cause.
Anyhow, I get my job done and I'd like to confirm that I have been working with the primary Aurora instance since the beginning, not replica.
Related
I dropped an entire database and am now trying to create a new database of the same name (a modified version of the old one, using an install script in case you are wondering why I am doing this).
The database fails on creation with a foreign key constraint (which is strange as the line of the sql file is way before I add constraints - the last time in the sql file).
Even stranger if I look in "information_schema" in the referential_constraints table I see the constraints still there from the schema I had dropped recently.
I am running MySQL community servers 8.0.22 under macOS Catalina. I have never had this behaviour that a constraint is free floating without an active schema that later invokes itself if you create a schema with that same name (note if I change the database name to any other name the SQL script loads no problem and creates the entire db)
I have one virtual machine (VM_A) that runs one mysql database DB_A schema with 200 rows in his tbl_1. In another virtual machine (VM_B) that runs a copy of the same DB_A schema I have 50 rows in the tbl_1.
I would like to update the DB_B with the data from DB_A.
The tbl_2 holds a foreign key from tbl_1.
I've already made a mysql dump from DB_A to run in DB_B, to be updated.
I do not want to use drop schema, before drop tbl_1.
If I try to run the code in DB_B I will have a error caused by foreign key constarint in tbl_2.
What could be the best approach to update the DB_B in this scenario?
I have already tested this solution but not worked https://dba.stackexchange.com/questions/40046/is-there-a-way-to-truncate-table-that-has-foreign-a-key
https://dba.stackexchange.com/questions/40046/is-there-a-way-to-truncate-table-that-has-foreign-a-key is ms sql-server. in mysql modify your session variables
SET FOREIGN_KEY_CHECKS=0;
Hy!
I have the following stupid question?
First an example to understand my point of view.
I have a mysql db, Innodb tables with foreign keys between them,
I currently work on a localhost machine
When I delete the last inserted record from a table let's say with primary auto-increment key set to
100 then the next primary key given by mysql is 101 but if I restart the mysql server (Apache server) then in the same table the primary key for the next record is reset to 100.
I have to mention that I set a trigger for the table I deleted the record from, to copy the deleted record to archive table before delete.
Now after mysql server was restarted if a new record is inserted it will get the primary key 100,and when I try to delete it a conflict appears because in the archive table there is already a primary key 100.
I have to keep the references between deleted key.
Now this happens only if mysql server is restarted.
The question is if this problem can be solved in case let's say that after the web application is deployed to a shared server host a server restart appears(I suppose).
I want to mention that the data base is moe complex the one table. I absolutely need to keep the integrity between archive tables after data is moved.
Error 1217: Cannot delete or update a parent row: a foreign key constraint fails
SQL Statement: drop table s_a_user.main
i used "rpl -Ris ..." to check the sql dumps, and it's not in there. i queried the information schema, and it's not in there either. i think this is a bug, but i may just not be finding an elusive reference to this table. screenshot below shows all info needed.
http://tinypic.com/r/30lcu2t/6 - they resized it and it's hard to read, but the tables listed are s_a_user.resume, not s_a_user.main, so, in other words, it confirms there is nothing referencing this
==UPDATE==SOLVED==
this is a bug in mysql. "SHOW ENGINE INNODB STATUS" shows the error came from "s_a_mail.topic", which does not even exist [-_-] ...
to solve this: delete all innodb log files, delete the schema, delete the schema's directory, restart mysql with innodb_force_recovery=4 in your my.conf, remove the force recovery, restart mysql again, recreate the database schema, reimport the data backup, restart mysql with innodb_force_recovery=4 AGAIN, take out innodb_force_recovery=4 and restart AGAIN.
this fixes the foreign key problem, but now workbench crashes when accessing the s_a_user schema's tables, so now i get to investigate that... [-_-] i'm about to just build a new database system...
SET FOREIGN_KEY_CHECKS=0; DROP TABLE ´your_table´; SET FOREIGN_KEY_CHECKS=1;
This should help you.
Trick from Rune Kaagaard on this question
I have a closed-source upgrade application which migrates my database from an old format to a new format (creates new tables and migrates data from the old to new tables).
The application crashes with a MySQLIntegrityConstraintViolationException. It doesn't give me the name of the table with the primary key violation or the contents of the broken SQL query.
Is there any MySQL server option that I can switch to give me more troubleshooting information? Maybe the text of the failed query or the name of the primary key constraint which is violated?
You can enable the general log file: http://dev.mysql.com/doc/refman/5.1/en/query-log.html . This way it might be possible to see at which point the server stops processing the queries.
You also can run the MySQL command show processlist to see what queries are being processed at that time.
Also have a look into all other application specific error logs.
A first try could be to disable foreign key checks during migration:
SET foreign_key_checks = 0;
A first guess would be, that the old server supported 0 as Primary Key values, whilst the new one does not.