InnoDB Corruption in Xampp - mysql

I have a backup from two weeks ago that will be a last resort, but the DB files themselves seem fine and it appears it's just the ibdata1 file that is having issues. As stated, I'm using Xampp and MySQL crashes right after I start it. Here is the error log: http://textuploader.com/7vfd
I hadn't done anything out of the ordinary; it seemingly just up and stopped working.
I looked up InnoDB recovery, but the solutions I tried required MySQL to be functional, which it isn't due to the corruption. Is there a way to salvage what are presumably intact IBD files with a bad ibdata1 file?
Edit: I was aware of using innodb_force_recovery = # and I had tried it...except I had tried it in the wrong my.ini. I had to use the one in the bin folder. It appears to be fixed now.

The ibdata1 file contains the tablespace information and other metadata about your Mysql database(s).
You can try using the innodb_force_recovery = 1 all the way to innodb_force_recovery = 6 to see if that rectifies the problem. Try changing this in your my.cnf (my.ini for windows) file and then attempt to restart your mysql server again.
If you are able to start Mysql using recovery flag, your database will be in a read-only mode. You should do a mysqldump of the data, stop mysql, re-install fresh, create your database again, and import back in the data.
Here is a link for more info on innodb recovery dev.mysql.
If you use linux...
Another more complex option is to use percona recovery tool kit. This will realign your tablespaces. Although, from experience its a bit of a challenge to navigate and takes a bit of time to implement if you are a newb.
However, akuzminsky the creator of the toolkit (how cool is that!) mentioned that he has made significant improvements to the toolkit.
Link to download toolkit Percona.com
Link with a walkthough from chriSQL.
Link to akuzinsky's website TwinDB.
Unless that data is mission critical, I would just revert back to the backup from 2 weeks prior. The amount of time and effort you may end up putting into recovering this data may out way the benefit.

In my case, the mysql.ini didn't have the innodb_force_recovery option.
So i added it to the file and the start was able to start normally
The location to the ini file for my case was
C:\xampp\mysql\bin\my.ini
innodb_force_recovery = 1
For my case, the data got corrupted after a disk check up by windows. In the due course, the database got corrupted.
Hope this can as well help someone out there.

on my case using xampp v3.3.3, i enable innodb_force_recovery = 6 in the top of my.ini configuration file and start the service from xampp dashboard.
also i clean up log, disable innodb_force_recovery = 6 and start again. it works like a charm

Related

Mysql Corrupt ibdata1 file prevents service from starting

I did a backup of the data folder from mysql server to keep all databases information.
C:\ProgramData\MySQL\MySQL Server 5.7\Data
I uninstalled MySQL server in Control Panel. I copied the data folder and pasted it back where it should be.
I am then trying to reinstall the service using MySQL installer. However, it is stuck on Starting Server... forever and sometimes will pop a message saying it is taking too long than expected. I tried this solution but it does not work for me.
When I remove the ibdata1, Mysql server installs, starts and runs. However, whenever I try to run a query on a table I get database_name.table does not exist.
Clearly to me the problem is ibdata1... So what should I do, if I really need to restore all the databases?
Do you still keep ibdata1 ? Reclean and copy back your ibdata1 and your data
For starting mysql, you should config Innodb force recovery (increase this value from 1 to 6). This will give you detail information https://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html
Remember, in recovery mode you can read data only and cannot update, insert or delete
Update:
Find your my.ini (on linux my.cnf) add this line to your [mysql]
innodb_force_recovery = 1
Try to increase it from 1 -> 6 until you can start your mysql server. Then you can perform dump to backup your server remember you cannot update/insert/delete in recovery mode

Sql databases get corrupt after every backup

I have a problem with my unix server. This started a week ago. One day after a backup (I used to keep 3 backup files) I visited a website on the server but it wouldn't work. I restarted the server and it seemed to be working fine except the mysql service. My attempts to restart it failed. Then I figured that was because the server was full, so I deleted one of the backups, cleaned up some space and the mysql service restarted successfully. Than I figured tables in one of the databases (MYIsam tables) were corrupt. So I repaired them through myisamchk command via ssh and all worked fine. However, the very next day I woke up they were corrupt again (despite mysql was working fine), and this time there was no disk space problem on the server. I repaired them again. The next day the same thing happenned; and this time innodb tables that were part of another database were corrupt as well. I've fixed them too, so now all is working well but I guess the same thing will happen after tonight's backup.
I can't identify the problem and I don't know what logs to look into to understand the problem. Can anyone please help me out? Thanks very much in advance.
No easy answer here. My immediate thought is that the dbase is still busy when the backups commence, possibly corrupting indexes, interferring with caches, etc. Turn on full logging and check for problems when the backup starts happens. Maybe you will find something.
Look for the my.cnf file. On my CentOs it is located in /etc/my.cnf. It will have a config setting for the location of the error log.
My strongest suspect is OOM kill by the kernel or some other issue that results from running the system out of memory. Try this:
Start top on the server and press M to sort by memory so the biggest memory user is at the top.
note the pid of mysqld
manually perform the backup as you observe the value of the RES column in the top output (resident memory size)
once the backup is over see if the pid of mysqld has changed
If the pid has changed (meaning restart took place), and you saw the memory footprint of mysqld take up something comparable to the total amount of system memory, then my suspicion is correct, and we need to lower some settings in my.cnf to make it use less memory, e.g key_buffer_size and innodb_buffer_pool_size.
EDIT - From the log you posted, there are additional issues although it is not clear how they could be contributing to the table corruption. Your server appears to be running with --skip-innodb and your backup script is not able to deal with the absence of InnoDB storage engine printing exception error messages, but nevertheless continuing. It is also attempting to do a repair, which is failing due to the lack of system privileges (error 1 is Operation not permitted). It is possible that encountering those errors triggers some faulty logic in your backup script that leaves the tables corrupted.
At this point I would recommend disabling MySQL backup using the cPanel tool, and using mysqldump or some other solution (e.g. Xtrabackup (https://www.percona.com/doc/percona-xtrabackup/2.3/index.html)) from a cron job instead.
EDIT2 - from the test results. The manual backup does not run the system out of memory and does not crash the server. The jury is still out on the automatic one.
Don't kill mysqld; shut it down gracefully.
Switch from MyISAM to InnoDB; the latter does not suffer from that 'error'.

MySQL crash -> innodb recovery not working -> trying another way

Good day to you.
I used my MySQL server with "innodb_file_per_table" option, and now server is crashed. I want to recover this server using this way:
Uninstall old MySQL
Install new MySQL
Add "innodb_file_per_table" in MySQL configuration
Copy databases folders (only my, not mysql) from old MySQL/data to new MySQL/data
In every folder I have two files, .frm and .ibd, and looks like this files have all data from my databases tables.
But, after copying, tables in this databases didn't work: when I try to open some table, I get error: Table xxx doesn't exist in engine.
I tried REPAIR command, but it isn't helpful.
If you know how to finish my way of repair — please help.
...I know that I need to copy ibdata1 also, but it looks so dead for recovery, so I try way that I try.
REPAIR command won't help with InnoDB.
If you're lucky enough the best you can do is:
1. Start MySQL with innodb_force_recovery=4 (try 5, 6 values if InnoDB fails to start). Make sure innodb_purge_threads=0.
2. Dump the database with mysqldump tool. Yes, it may be slow, but there is no other choice.
3. Create new empty InnoDB table space and reload the dump.
If MySQL fails to start with innodb_force_recovery=6, then recovery from backups is the only option. Well, you can fetch records from *.ibd files, but this is tedious job - google data recovery tool from percona
UPDATE: Data recovery toolkit moved to GitHub
You need to copy everything, not only the data folder
For example, without the ibdata file, mysql don't know where the tables are stored.
https://serverfault.com/questions/487159/what-is-the-ibdata1-file-in-my-var-lib-mysql-directory

1067 error on attempt to start MySQL

I've installed MySQL on Windows 7. When I'm trying to start MySQL service I'm getting error 1067: The process terminated unexpectedly. Log message:
101111 22:27:11 [Note] Plugin 'FEDERATED' is disabled.
C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqld: Table 'mysql.plugin' doesn't exist
101111 22:27:11 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
InnoDB: Log scan progressed past the checkpoint lsn 0 37356
101111 22:27:11 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 0 44233
101111 22:27:11 InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 86 87 88 89 90 91 92 93 94 95 96 97 98 99
InnoDB: Apply batch completed
101111 22:27:12 InnoDB: Started; log sequence number 0 44233
101111 22:27:12 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
What can I do about it?
The solution was to install MySQL without spaces in installation path.
Windows 7, 64-bit
One more thing that prevents the mysqld windows service from running is if you have mysqld.exe already running (but not as a service) and occupying port 3306. When the service tries to start and sees that port 3306 is already taken, it fails.
Just open up the windows task manager and look for "mysqld.exe" under the Processes tab. If you see it, kill it and then try to start the service again.
c:\> net start [servicename]
example: c:\> net start MySQL
My issue happened right after a power failure. I got the error 1067 The process terminated unexpectedly. MySQL needless to say did not start. The answer was simple
Open mysql path\data
Remove (delete) both ib_logfile0 and ib_logfile1.
Start the service
The solution to the problem for me was looking in my install directory, finding the /data folder, and copying it's content to the data folder that was specified in my .ini/.cnf configuration file.
I just encountered a similar issue and I found that it is a permission problem. When I copy the database "data", I have to add the permission for "NETWORK SERVICE"
I had the same problem. In my case, it was "user error" (although the Windows installer should have been smarter about it and prevented me from committing such an error).
During installation, if you make changes to the default installation paths, make sure you use the same paths for both the "Server data files" on the Custom Setup screen and then later in the "InnoDB Tablespace Settings" during the "MySQL Server Instance Configuration Wizard"
I had a problem changing the datadir in my.ini for Windows 7.
I wanted the data to be stored on a different drive and I was moving this data from another PC by copying the whole folder. I changed datadir to desired drive and saved the my.ini file with no problems.
But mysql would not start. I opened my.ini file again and it appeared to have been changed.
Then, I noticed the date on the my.ini had not changed. So I had to change the security privileges to give me write access to it.
This time when I saved it, the date changed and mysql started up access to all the correct data.
Before messing with too much things, please check the user the service is trying to run as. In my case it was NETWORK this one did not have write permissions to some locations where it was needed. Changing the user to Local System Account did the trick. If the event viewer shows any error like "Can't create test file C:\Program Files\MySQL\MySQL Server 5.6\data\XXX.lower-test", there is a high probability for this solution to work.
Good luck!
I have mysql data folder replaced by a windows directory junction.
I suspect ib_logfile0/1 and/or ibdata1 is corrupted.
Just try to delete those files and computername.err. Then restart mysql service.
That's what I did, with success.
Copying ibdata1 files, after a full reinstallation of mysql, to the junction dir and replacing dir by the junction, restarting mysql, was not enough.
You have to let mysql rebuild those files.
Also check if all dirs which you wrote in the my.ini exists.
My problem was that tmpdir doeesn`t exist so MySQL daemon falls with error 1067.
[mysqld]
port= 3306
tmpdir = "C:/tmp"
In this case C:/tmp must exists.
Check the file "C:\Program Files\MySQL\MySQL Server 5.1\my.ini"
The datadir line in my.ini should specify a path. Check the contents of that datadir path. Does it contain a folder named "mysql" and another folder named "test"?
If not, here are two choices:
Change the datadir line in my.ini to the correct location. This will probably be C:\ProgramData\MySQL\MySQL Server 5.1\data
Clean out the existing contents of your datadir path. Copy the contents of the C:\ProgramData\MySQL\MySQL Server 5.1\data to your datadir path. Restarting the mysql service should rebuild your empty database.
In my instance it had nothing to do with spaces in the file name. I used the MSI installer custom configuration and opted to exclude the default databases, assuming it was just something like Northwind/Adventureworks. Nope, it includes the core MySql system database... once I added that to the installation it worked.
in my case innodb_data_home_dir was no longer correct because I had shuffled some drive letters around when I added a new drive to my system
In my case, I have unzipped XAMPP ina a second disk on my installation, "F". When I tried to start as a service, the return was "1067". The solution was to edit my.ini, inserting the "f:" drive in the files lines. It solved the problem.
The problem look like there is no data in the directory.
copy at least the mysql directory either from your previous directory or from C:\Program Files\MySQL\MySQL Server 5.5\data .
And then try again.
I had the same error and it was caused by non standard characters in the log files path.
In order to fix that I found my.ini config file (in my case C:\ProgramData\MySQL\MySQL Server 5.6\my.ini) and modified keys slow_query_log_file and log-error.
After that I managed to start MySQL service succesfully.
In my case, I had chosen a custom path for my log-files in the MySQL installer. I had put the log-files in my user-folder C:\Users\%MY_USERACCOUNT%\Documents\mysql-logs, and by default, NETWORK SERVICE (or any other non-administrator useraccount in Windows) does not have access to a user's folder.
I fixed this by changing security options for the log-folder, giving modify rights read/write/modify rights to NETWORK SERVICE.
I also get log with Table 'mysql.plugin' doesn't exist
if install MYSQL Server 5.1 by 'msiexec.exe'
DataDir I put as C:\MYSQL\MySQL_Server_5_1\data\
but to my surprise was create data in a C:\MYSQL\MySQL_Server_5_1\data\data
There are was add word data . So I change my.ini file from
datadir="C:/MySQL/MySQL_Server_5_1/Data/" .
to the
datadir="C:/MySQL/MySQL_Server_5_1/Data/data"
and then I can use
net start MYSQL51
and then mysqld.exe run and appear in a Task Manager
when looked at mysql log (.err file under data folder), i could see the following
21:41:47 UTC - mysqld got exception 0xc0000005 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
Attempting to collect some information that could help diagnose the problem.
As this is a crash and something is definitely wrong, the information
collection process might fail.
I realized i was starting the service while i plugged usb. To be honest, the problem was resolved after i restarted my machine followed by restarting the service. In addition i removed ib_logfile0 and ib_logfile1 files before my restart. Though the event logger indicated "InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information
Blockquote
about forcing recovery.For more information, see Help and Support Center at http://www.mysql.com", i do not think so because i never changed any configurations.
Experienced the same error, below is the reason and solution that worked for me for mysql-5.7.14-winx64
reason: DATA folder to have some default folders and files which were missing
solution: delete everything from DATA folder, i assume its a fresh installation so backup anything that you need if at all. Then run this from the command prompt and it will create required files and folders
"mysqld --initialize --console"
now run "mysqld" and it should work well.
In my case, I had another MySQL version installed and running.
I found this by going into the mysql_error.log file.
I fix this by going to services and stopping the running MySQL version and setting up to a manual, and starting the mysql needed.
...an old one... anyway I had the same issue with MariaDB
In my case most pathes contain special characters like: #
Wrapping pathes in my.ini in double quotes made the trick - e.g.
datadir="C:/#windata64/db/MariaDB/data"
In my case, in order to delete a heavy schema from mysql server, just went to C:\ProgramData\MySQL\MySQL Server 5.7\Data and deleted relevant folder. But it was not being deleted because mysqld.exe was preventing it. so I stopped mysqld.exe, deleted the folder and then all the schemas went disappeared from the list in mysql workbench. No matter how much I tried to restart mysql service, it didnt unless I restored that folder from junk.
Hope it helps someone who tried the same shortcut as I did.
I run MariaDB (MySQL compatible) on two machines locally. I'm not sure what prompted the error and nothing I tried worked. So I stopped the service, deleted everything in MariaDB's directory (except the data directory) and copied the files from my secondary machine and everything is working well enough as far as I can tell.
For a live server it'd be a bit different and a super-guru might be able to add an insight comment (e.g. something outside of the data directory might have something to do with preventing data corruption or indexes in example?). I would just stop the service and copy the entire directory once every month or so and then start the service again.
I ran into the same errors. Similar approach for me. From what I can tell, there is something weird going on with the reference to the datadir in the my.ini file. Even when I manually edited it I could not seem to have any effect on it, until I blew EVERYTHING AWAY. Wish I had better news...do a DB backup first.
For me the key to getting this to work was:
1) Remove the previous installation from settings->control panel. Restart your machine.
2) Once machine comes back up, forcefully delete the previous installation directory.
[mine is C:\apps\MySQL\MySQLServer-5.5\, as I REFUSE to use c:\program files\..]
3) Forcefully delete the previous datadir directory [mine was c:\data\mysql].
4) Forcefully delete the previous default data directory [C:\Documents and Settings\All Users\Application Data\MySQL].
5) Re-run the install, selected the same installation directory. Skip the instance configurator/wizard at the end of the install.
6) Make sure the ../bin directory gets added to the path. Verify it.
7) Manually run the instance configurator/wizard.
Set the root password, port [3306].
It will try to start it. Again, mine FAILED to start
[duh! nothing new there!!!]
8) Now, manually edit the my.ini file in the install directory, and correct the datadir setting to be [datadir="C:/Data/MySQL/"] MATCH CAPITALIZATION !!!!
9) Verify the service is setup correctly via the command-prompt [sc qc mysql <enter>].
Should look like:
C:\dev\cmdz>sc qc mysql
[SC] GetServiceConfig SUCCESS
SERVICE_NAME: mysql
TYPE : 10 WIN32_OWN_PROCESS
START_TYPE : 2 AUTO_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : "C:\apps\MySQL\MySQLServer-5.5\bin\mysqld" --defaults-file="C:\apps\MySQL\MySQLServer-5.5\my.ini" MySQL
LOAD_ORDER_GROUP :
TAG : 0
DISPLAY_NAME : MySQL
DEPENDENCIES :
SERVICE_START_NAME : LocalSystem
10) Copy the contents of the default data-directory created under C:\Documents and Settings\All Users\Application Data\MySQL [basically everything in this directory to your desired data directory c:\data\mysql]. Make sure you get the C:\Documents and Settings\All Users\Application Data\MySQL\mysql directory. This has host.frm file, and others.
You should end up with a directory now of c:\data\MySQL\mysql...
11) Rename the default directory
C:\Documents and Settings\All Users\Application Data\MySQL
To
C:\Documents and Settings\All Users\Application Data\MySQLxxx
So it cannot find it...
12) Say a quick prayer...
13) Give it a kick start from command line with [net start mysql]
That got it working for me...
Best of Luck!
Something I just discovered was that in the setup I choose InnoDB, whereas in fact all my existing databases were in MyIsam format. I uninstalled and then re-installed choosing MyIsam and everything worked just fine.
If you are trying to run MySql on a Windows 10 installation with a GPT partition, please try this:
Todays systems are often running on a disk which is formatted in GPT. This is because Windows 10 needs such a partition to be installed. The problem is that MySql cant deal with this partition style and so it crashes. Here is my workaround:
Create a virtual disk: manual here
Format this VHD with MBR
Install MySql custom on your new VHD (dont forget to create a user for DB)
This should be it! :)
Reference Link:
Issue with MySql installation on Windows 10

Include ib_logfiles in backup?

The short question:
Is it safe skip ib_logfile* files while creating custom-made backup of MySQL installation with InnoDB engine used?
Custom-made backup is just copy all (or subset of) /var/lib/mysql + /etc/my.cnf to safe place.
As I know ib_logfile* files are recreated by MySQL on start + the files are really huge, so that may not be wise to store them in backup. And yes, assume MySQL is (correctly) stopped before backup.
It's not safe to back up a database in the manner you're describing.
The reason is that you cannot know if some data pages are still in MySQL Server's memory, pending an I/O flush to disk. So copying the files has a good chance of copying garbage, whether or not you include the ib_log files.
Don't do what you're doing. Use mysqlbackup or InnoDB's Hot Backup product.
edit:
Read Farhan Mashraqi's blog article about InnoDB Performance Optimization, in which he says you can delete the ib_log files if you have shut down MySQL Server.
InnoDB log resizing: is not as simple
as changing option and restarting. You
need to shut down MySQL server and
make sure it shuts down normally
(check error log for errors to
confirm). Then move away InnoDB log
files ib_log*. Then start the MySQL
server and check error log files to
see if it successfully created new log
files.
So yes, you should be able to do a filesystem copy of the ibdata files only. You don't need to include the ib_log files, because they should be recreated as MySQL Server starts up. I reiterate, however, that I do not recommend backing up databases with filesystem copy.
Suppose you back up a database today in this manner, using MySQL 5.0. Someday later you need to restore the backup, but by that time you'll be using some future version like MySQL 6.5 for example. Do the ib_data files still use the same internal format in that future version? Will MySQL 6.5 read those files you backed up today? You can't be sure. The backup format is intended to be more portable.