Sometimes tables in the mySQL database crash after a server restart or after a lost connection to the database.
This have happen several times for the last 3-4 weeks.
This is how the error message looks like:
145 - Table './xxx/sessions' is marked as crashed and should be
repaired select value from sessions where sesskey =
'60fa1fab3a3d285cfb7bc1c93bb85f64' and expiry > '1395226673'
[TEP STOP]
So far it’s have been the tables "sessions" and "whos_online" that have crashed. If I repair the tables in phpmyadmin it will work fine again
After the last crash I changed "sessions" from MyISAM to InnoDB. The table "whos_online" still use MyISAM.
I use osCommerce 2.2 rc2a and I'm looking for any thoughts and suggestions in this matter.
One solution might be to change both these tables to InnoDB, since it supposed to be self-healing. Is that a good or bad idea?
Another one would be to have them in MyISAM and do something like this with the php-file that echo the error message:
if $error contain "is marked as crashed and should be repaired"
run a table repair script
Would that be a good or bad idea?
Here’s my server specs
Database: MySQL 5.5.36-cll
PHP Version: 5.3.15
At first you should address the issue that tables become corrupted in the first place. InnoDB tries to repair broken files, but it cannot do magic. Repeated unsafe shutdowns or other accidents may seriously corrupt your database!
If you only have a small website, all variants are good. MyISAM is a little faster (sometimes), while InnoDB provides some extended features. If the server is strong enough, you will likely encounter no issues. I would stick with InnoDB in most cases as it accounts for consistent data and throws errors if files are broken, unlike MYISAM tables which are used and then sometimes throw errors in production...
But if something severely breaks, it requires more effort to get MySQL with InnoDB back up running if it does not automatically. There exist different InnoDB recovery modes which are only available from the shell of your server and require modifying the config file, starting the server by hand, reading its output and maybe doing some other actions. If you do not have any clue of these issues, you might want to stick with MyISAM instead. The server always starts, and if the table is utterly broken, you might need to import a backup. But this is more easily than editing config files and reading database outputs etc.
Related
everyone! I'm trying to avoid breaking of my database in the phpbb3.1 forum. It was crushed twice this month.
So I have two questions:
1) Is it safe to convert MyISAM to InnoDB? I mean will extensions work fine? Will forum be workable after updating to next version?
2) In which way I can avoid base corrupting?
p.s.
I also posted this question here:
https://www.phpbb.com/community/viewtopic.php?f=466&t=2436326
I'll venture a guess. You had a power failure, and when it came back up, MySQL was complaining that some index on some table was corrupted? And that table was MyISAM?
Use myisamchk to repair the tables.
Review the gotchas in http://mysql.rjweb.org/doc.php/myisam2innodb to see if conversion to InnoDB will add new woes. There probably won't be any. A 2-part PRIMARY KEY is about the only thing that is not implemented in InnoDB. Also, if you have too old a version of MySQL, InnoDB may not yet have FULLTEXT indexes (if you need them).
Change my.cnf: key_buffer_size = 20M and innodb_buffer_pool_size equal to about half of available memory.
ALTER TABLE xx ENGINE=InnoDB; for each table xx.
I think (but am not sure) that each update/delete/insert marks the table as possibly corrupt. It writes the changes, but does not clear the mark. When mysqld shuts down cleanly, everything is flushed to disk and these flags are cleared. When mysqld comes back up, it complains about the flags that did not get cleared. So...
Whether or not an index is marked as corrupt depends solely on whether you modified that index and crashed. (Every table has some index, yes?)
Normally, MySQL manages to flush changes to disk before a crash. Only occasionally does the crash happen at a time where the index will really be corrupt. There is a "quick" mode on the repair that simply clears the flag -- you could try that. But if you ever get a mysterious "can't find record" when you know the records exists, you'd better REPAIR it.
We recently ran a script against a mysql to convert all tables to use innodb. Unfortunately, this also included the system tables. The server will no longer start.
I didn't figure it would probably matter in this case, but also tried the
innodb_force_recovery in the config file and restarting. Same error.
Is there any way to get back to myisam from this dumb conversion on the system tables?
Dump we're receiving
Thread pointer: 0x92eb40
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
000000014009A9A1 mysqld.exe!ha_resolve_by_name()[handler.cc:135]
0000000140119F6F mysqld.exe!open_binary_frm()[table.cc:897]
000000014011C12B mysqld.exe!open_table_def()[table.cc:644]
0000000140078204 mysqld.exe!get_table_share()[sql_base.cc:379]
000000014007829D mysqld.exe!get_table_share_with_create()[sql_base.cc:478]
000000014007A9B3 mysqld.exe!open_unireg_entry()[sql_base.cc:3874]
000000014007E0C1 mysqld.exe!open_table()[sql_base.cc:2931]
000000014007ED61 mysqld.exe!open_tables()[sql_base.cc:4630]
000000014007F258 mysqld.exe!open_and_lock_tables_derived()[sql_base.cc:5041]
000000014003643C mysqld.exe!plugin_load()[sql_plugin.cc:1417]
000000014003772A mysqld.exe!plugin_init()[sql_plugin.cc:1252]
000000014001DB5E mysqld.exe!init_server_components()[mysqld.cc:4021]
000000014001E315 mysqld.exe!win_main()[mysqld.cc:4490]
000000014001E6AF mysqld.exe!mysql_service()[mysqld.cc:4666]
00000001402EBAB7 mysqld.exe!_callthreadstart()[thread.c:295]
00000001402EBB85 mysqld.exe!_threadstart()[thread.c:275]
0000000076C7A4BD kernel32.dll!BaseThreadInitThunk()
0000000077076461 ntdll.dll!RtlUserThreadStart()
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (0000000000000000): =
Connection ID (thread ID): 0
Status: NOT_KILLED
Yeah, that is bad news. The mysql tables should not be converted from MyISAM; MySQL cannot work if they are.
Plan A: If you have any sort of dump, reload at least the database mysql from that dump. Then we can discuss how to get your tables loaded or whatever.
Plan B: Install a new copy of MySQL; it will have 'correct' in mysql (but won't have your GRANTs, etc.) Then we can discuss how (and whether) you can get your tables reloaded/rebuilt.
What dump(s) do you have? Recent? Old? In MyISAM? In InnoDB? What was the value of innodb_file_per_table? What version are you coming from / going to? (There, I am thinking about "transportable tablespaces".)
Won't help at the moment, but you should review the other gotchas in the conversion: http://mysql.rjweb.org/doc.php/myisam2innodb .
We have a website that has a table of tax rates that somehow got corrupted one day.
I tried selecting * from theTable but it literally took hours to yield nothing.
I tried truncating and dropping the table. Produced the same results as the select.
Eventually the actions stopped. So, I ran a
myisamchk -r theTable.MYI
Repaired looks like it went okay, but I tried selecting * from it again and still producing the same results.
Engine is MySQL
It would be easy to reproduce the table, can I just delete theTable.* (frm, MYD, MYI)?
Or if there is a better approach to what I'm doing.
Yes, you can delete the .FRM, .MYD, .MYI files to remove a MyISAM table. This is what happens when you DROP TABLE.
MyISAM tables are infamous for getting corrupted. But the fact that you got repeated problems after recreating the table makes me wonder if you have a failing hard drive. It would be worth testing the health of your hard drive.
You should also switch to use InnoDB instead of MyISAM. InnoDB has a lot of protections against corruption, including page checksums, synchronous disk writes, crash recovery, etc. MyISAM is being slowly phased out and is receiving no fixes from MySQL developers. InnoDB is now the default storage engine as of MySQL 5.5 (circa 2010), and it will continue to be the focus of future development.
Note that with InnoDB, you cannot simply delete files to achieve dropping a table like you could with MyISAM. You must use DROP TABLE so InnoDB synchronizes that drop with its internal data dictionary.
I have a mysql server with production database and a staging database. I am using innodb for the production tables, but I don't need the features for staging which just moves data around. So I decided to switch those tables to myisam expecting an increase in insert performance.
The results were horrible. It looked more like inserting into an innodb table without autocommit disabled. If I keep the table innodb and turn off autocommit during the insert I can get several thousand inserts per second. As soon as I change the table to myisam I'm getting maybe a couple dozen inserts per second.
I thought maybe it was because I'm getting the data via our legacy backend using SSIS but that doesn't appear to be the issue. Using SSIS and going from our production db to the staging db (mysql to mysql) I still see the same results... innodb(no autocommit) far out performs myisam.
This makes no sense to me. If nothing else, in my experience, myisam should at least be comparable, hopefully even better.
Is there anything obvious I am overlooking? I haven't included specifics in hopes that it is something in general I am missing.
EDIT:
This appears to be related to SSIS and the ODBC Destination component. I'm using an ODBC Source that has my select statement and the output goes to the ODBC Destination which is table on the same server, but a different DB. Since the DBs are on the same server I ran, in SqlYog, an INSERT using the same SELECT query as the ODBC Source and it finished in a couple seconds. I will see if I can find a solution.
sometimes i get an error like "table is marked as corrupt and shld be repaired". that DB (tables) is using MyISAM. recently that keeps happening. what could be the causes? most recently i am executing a batch insert
INSERT INTO table (..., ..., ...) VALUES (...), (...), (...) ...
and it just hung. or took very long to complete it seems hung to me. the next day, when i checked the table was marked as corrupt again. when i try to use mysqlcheck -r it said all tables OK when it reached that "corrupt" table it hung there again...
so, what can i do to prevent this. and what could be the causes. the DB is hosted 3rd party, how can i debug this?
is InnoDB a more reliable engine to use? i heard MyISAM is faster but others say InnoDB can be fast also but it takes abit more to optimize it. can i conclude that InnoDB is something more reliable but abit slower overall even with optimization?
If your tables get corrupt, you can use the repair table command to fix them:
REPAIR TABLE table;
If you run myisamchk while the server is still running (and inserts/selects are hitting the table), it could be what is corrupting your tables. Most of the corruption issues I run into are when trying to do things outside the server (copying the files, etc) while it is still running.
InnoDB is slower for read only databases, because it has features (ACID compliant, row level locking) that MyISAM leaves out. However, if you are doing a mixture of reads and writes, depending on the mixture, then InnoDB can offer serious performance improvements, because it doesn't have to lock the entire table to do a write. You also don't run into corruption issues.
Go with InnoDB.
ok, so the problem was the company's db exceeded the storage space allowed by the hosting company. so apparently noone told the company they exceeded the usage ... lousy host i guess.
btw, theres no way mysql could have known abt this?