how to recover a corrupted MySQL InnoDB data file - mysql

My MySQL has been crashed due to I/O issue and the InnoBD data file has been corrupted, I get the following message whenever I try to copy or move the data file:
cp: reading `ibdata1': Input/output error
cp: failed to extend `/root/ibdata1': Input/output error
I also found this error in logs:
mysqld: InnoDB: Error: tried to read 16384 bytes at offset 0 10665984.
mysqld: InnoDB: Was only able to read 8192.
mysqld: 150518 9:00:17 InnoDB: Operating system error number 2 in a file operation.
mysqld: InnoDB: The error means the system cannot find the path specified.
mysqld: InnoDB: File operation call: 'read'.
mysqld: InnoDB: Cannot continue operation.
How can I fix this?

Related

innodb crashed with error number 5 and mysql wont start

hello my database stop today and dont start again.
2019-12-10 10:08:02 26295 [Note] InnoDB: Completed initialization of buffer pool
2019-12-10 10:08:03 26295 [ERROR] InnoDB: Error in system call pread(). The operating system error number is 5.
2019-12-10 10:08:03 7f21d3356780 InnoDB: Operating system error number 5 in a file operation.
InnoDB: Error number 5 means 'Input/output error'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.6/en/operating-system-error-codes.html
2019-12-10 10:08:03 26295 [ERROR] InnoDB: File (unknown): 'read' returned OS error 105. Cannot continue operation
please help me i lost the database data. can start again the mysql and get data or resolve this error? thank you.

mysql not starting on mamp

I've been using MAMP for quite a while now but a few months ago it started to give me issues. I've since looked online through google searches and stack overflow to find a resolution but I haven't seen anything that could help me yet.
I've searched for some articles but these that I felt would have been close to helping me did not:
MAMP mysql not starting
I'm not sure the path to my data directory? and anything I type in the terminal seems to come back as commmand not found
Mysql service won't start, InnoDB init function error
MAMP mysql server won't start. No mysql processes are running
I attempted to killall but "No matching processes belonging to you were found" error was shown
About an hour ago my mqsql was working but not apache, so I found as article that said to rename Library/bin/envvars to _envvars, apache worked on startup but then mysql didn't.
I'm not getting any errors in my php log but here is my apache and mysql logs.
Here is a snippet from the bottom of the mysql error log
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 35
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 35
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 35
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 35
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 35
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 35
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 35
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 35
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 35
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 35
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 35
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 35
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
170118 15:52:39 InnoDB: Unable to open the first data file
InnoDB: Error in opening ./ibdata1
170118 15:52:39 InnoDB: Operating system error number 35 in a file operation.
InnoDB: Error number 35 means 'Resource temporarily unavailable'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/operating-system-error-codes.html
170118 15:52:39 InnoDB: Could not open or create data files.
170118 15:52:39 InnoDB: If you tried to add new data files, and it failed here,
170118 15:52:39 InnoDB: you should now edit innodb_data_file_path in my.cnf back
170118 15:52:39 InnoDB: to what it was, and remove the new ibdata files InnoDB created
170118 15:52:39 InnoDB: in this failed attempt. InnoDB only wrote those files full of
170118 15:52:39 InnoDB: zeros, but did not yet use them in any way. But be careful: do not
170118 15:52:39 InnoDB: remove old data files which contain your precious data!
170118 15:52:39 [ERROR] Plugin 'InnoDB' init function returned error.
170118 15:52:39 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
170118 15:52:39 [ERROR] Unknown/unsupported storage engine: InnoDB
170118 15:52:39 [ERROR] Aborting
170118 15:52:39 [Note] /Applications/MAMP/Library/bin/mysqld: Shutdown complete
170118 15:52:39 mysqld_safe mysqld from pid file /Applications/MAMP/tmp/mysql/mysql.pid ended
and then the apache error log
[Wed Jan 18 15:48:28 2017] [notice] Digest: generating secret for digest authentication ...
[Wed Jan 18 15:48:28 2017] [notice] Digest: done
[Wed Jan 18 15:48:28 2017] [notice] Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8zh DAV/2 PHP/5.3.6 configured -- resuming normal operations
[Wed Jan 18 15:48:31 2017] [notice] caught SIGTERM, shutting down
[Wed Jan 18 15:51:01 2017] [notice] Digest: generating secret for digest authentication ...
[Wed Jan 18 15:51:01 2017] [notice] Digest: done
[Wed Jan 18 15:51:01 2017] [notice] Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8zh DAV/2 PHP/5.3.6 configured -- resuming normal operations
My ports are: apache 80 and mysql 3306.
If anyone might know what might be happening that would be amazing..
Back in December, when I had this same problem in my Mac, I explored a bit and found a very simple solution:
Quit MAMP
In the finder go to Applications/MAMP/db/mysql56/ and delete the last log file, in my case ib_logfile1. (It might be a good idea to back up this file before deleting it, or alternatively move it to a different location instead of deleting it.)
Restart MAMP. That's it!
Some people had reported that deleting also ib_logfile0 was necessary, but not in my case. You can check this in JuanFra.me blog where I first posted my solution last year.
I don't know why or how this solution worked, but it seems that it has been helpful to many others, as reported in JuanFra's blog. I hope it is useful to you as well.
Another copy of MySQL/MariaDB currently running?
ibdata1 on some odd file system partition?
Did you by chance restore from a backup taken from an instance that was up?
The following is excerpted from https://dev.mysql.com/doc/refman/5.7/en/backup-types.html
Physical backup methods have these characteristics:
• Backups can be performed while the MySQL server is not running. If the server is running, it is necessary to perform appropriate locking so that the server does not change database contents during the backup. MySQL Enterprise Backup does this locking automatically for tables that require it.
To stop MySQL There are different cases depending on whether you installed MySQL with the official binary installer, using MacPorts, or using Homebrew:
MacPorts
sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql.plist
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql.plist
Note: this is persistent after reboot.
Homebrew
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Binary installer
sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
sudo /Library/StartupItems/MySQLCOM/MySQLCOM restart
If MySQL isn't starting it is pretty likely that it could already be running. You can very easily manually turn it off in the terminal.
I've had this happen to me a few times and I believe it has something to do with not shutting MAMP off correctly.
Quit MAMP.
Open the terminal and type: killall -9 mysqld
Restart MAMP.
Quit MAMP
go to /Applications/MAMP/tmp/mysql/ and add file
Restart MAMP. That's it!

Cannot start mysql after restart on Yosemite

I'm having a problem that appears to be fairly commonplace, though having read around and attempted numerous solutions I'm quite confused as to what's going on here. The crux of the problem is, ever time I restart my Mac (running on OS X Yosemite 10.10.3) after installing MySQL it cannot connect, start or function, with the following message displayed ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2).
I have installed MySQL using brew, where it resides in /usr/local/Cellar/mysql/5.6.26/. When I run mysqld_safe from here it quits each time, failing to start. I've looked at the error file and these are the error messages:
2015-09-16 10:43:27 7fff77882300 InnoDB: Operating system error number 2 in a file operation.
InnoDB: The error means the system cannot find the path specified.
InnoDB: If you are installing InnoDB, remember that you must create
InnoDB: directories yourself, InnoDB does not create them.
2015-09-16 10:43:27 1421 [ERROR] InnoDB: Could not find a valid tablespace file for 'bespokedb/concept_terms'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2015-09-16 10:43:27 1421 [ERROR] InnoDB: Tablespace open failed for '"bespokedb"."concept_terms"', ignored.
2015-09-16 10:43:27 7fff77882300 InnoDB: Operating system error number 2 in a file operation.
InnoDB: The error means the system cannot find the path specified.
InnoDB: If you are installing InnoDB, remember that you must create
InnoDB: directories yourself, InnoDB does not create them.
2015-09-16 10:43:27 1421 [ERROR] InnoDB: Could not find a valid tablespace file for 'bespokedb/terms'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2015-09-16 10:43:27 1421 [ERROR] InnoDB: Tablespace open failed for '"bespokedb"."terms"', ignored.
2015-09-16 10:43:27 1421 [Note] InnoDB: 128 rollback segment(s) are active.
2015-09-16 10:43:27 1421 [Note] InnoDB: Waiting for purge to start
2015-09-16 10:43:27 1421 [Note] InnoDB: 5.6.26 started; log sequence number 12730080990
Warning: World-writable config file './auto.cnf' is ignored /usr/local/Cellar/mysql/5.6.26/bin/mysqld: Error on delete of './auto.cnf' (Errcode: 13 - Permission denied)
2015-09-16 10:43:27 1421 [Warning] World-writable config file './auto.cnf' has been removed.
Warning: World-writable config file './auto.cnf' is ignored
2015-09-16 10:43:27 1421 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 617f6dd0-5c57-11e5-a7aa-9c9a2e17ea50.
I have tried making the mysql data dir (which is in /usr/local/var/mysql) folders and files read, write and executable (a bit naughty I know). I've also tried creating a sim link for the mysql.sock in /var/mysql/. Aside from that I've uninstalled and reinstalled mysql numerous times and have followed many routines detailed online on how to remove/add startup items. All in all, this seems very overcomplicated for a very widely used piece of kit on a very widely used operating system. If somebody would be very kind to go into some detail here about how these problems might be arising / why this process isn't more simple that would be brilliant. I only want to learn!
Thanks,
Dan

Error 1067: The process terminated unexpectedly [InnoDB]

I am facing the following error when i try to restart the MySQL service after an unexpected shutdown of the database server last night.
Could not start the MySQL service on Local Computer.
Error 1067: The process terminated unexpectedly.
When i check the .err log file under MySql data folder, the log details are as per below.
InnoDB: Log scan progressed past the checkpoint lsn 804 2135184621
150513 12:20:39 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 804 2136195241
150513 12:20:50 InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 0 1 2 3 150513 12:20:50 InnoDB: Assertion failure in thread 2412 in file .\rem\rem0rec.c line 337
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http:// bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http:// dev.mysql.com/doc/refman/5.1/en/forcing-recovery.html
InnoDB: about forcing recovery.
150513 12:20:51 - 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.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.
key_buffer_size=135266304
read_buffer_size=65536
max_used_connections=0
max_threads=400
threads_connected=0
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 262617 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.
thd: 0x0
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...
InnoDB: Thread 164 stopped in file .\os\os0sync.c line 391
0070A1A8 mysqld.exe!rec_get_offsets_func()[rem0rec.c:337]
0071B498 mysqld.exe!page_cur_parse_insert_rec()[page0cur.c:798]
0071512F mysqld.exe!recv_parse_or_apply_log_rec_body()[log0recv.c:814]
00715CF1 mysqld.exe!recv_recover_page()[log0recv.c:1294]
006EBE0F mysqld.exe!buf_page_io_complete()[buf0buf.c:2033]
006E4472 mysqld.exe!fil_aio_wait()[fil0fil.c:4273]
006BCDCD mysqld.exe!io_handler_thread()[srv0start.c:437]
77E6482F kernel32.dll!GetModuleHandleA()
The manual page at http:// dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
Error log show in Event Viewer:
An unhandled win32 exception occurred in mysqld.exe [1200]. Just-In-Time debugging this exception failed with the following error: Debugger could not be started because no user is logged on.
MySQL version: 5.1<br>
Table Type: InnoDB<br>
ibdata1 Size: 28GB
There are no SQL dump backup files for the tables made and there is only the SQL physical data files. I am desperately needed to restore the data of these and bring the website back to online.
Please help.
Apparently this is a known bug within MySQL 5.1 as mentioned within a few bug docs below.
http://bugs.mysql.com/bug.php?id=44416
http://bugs.mysql.com/bug.php?id=45844
I have updated the MySQL version to the latest (5.1.73) and then force recovery the InnoDB at level 6 (can only be started at this level for my case). After that, i can proceed with mysqldump.
setting file my.ini
change or add setting
innodb_flush_method=normal
restart service mysql

Checking for tables which need an upgrade, are corrupt or were not closed cleanly

I am running mysql on my EC2 and when I tried to do:
sudo /etc/init.d/mysql restart
I got this:
Stopping MySQL database server mysqld
Starting MySQL database server mysqld
Checking for tables which need an upgrade, are corrupt or were not closed cleanly.
Here is what is in my /var/log/mysql/error.log
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
140406 1:47:27 InnoDB: Unable to open the first data file
InnoDB: Error in opening ./ibdata1
140406 1:47:27 InnoDB: Operating system error number 11 in a file operation.
InnoDB: Error number 11 means 'Resource temporarily unavailable'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/operating-system-error-codes.html
140406 1:47:27 InnoDB: Could not open or create data files.
140406 1:47:27 InnoDB: If you tried to add new data files, and it failed here,
140406 1:47:27 InnoDB: you should now edit innodb_data_file_path in my.cnf back
140406 1:47:27 InnoDB: to what it was, and remove the new ibdata files InnoDB created
140406 1:47:27 InnoDB: in this failed attempt. InnoDB only wrote those files full of
140406 1:47:27 InnoDB: zeros, but did not yet use them in any way. But be careful: do not
140406 1:47:27 InnoDB: remove old data files which contain your precious data!
140406 1:47:27 [ERROR] Plugin 'InnoDB' init function returned error.
140406 1:47:27 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140406 1:47:27 [ERROR] Unknown/unsupported storage engine: InnoDB
140406 1:47:27 [ERROR] Aborting
140406 1:47:27 [Note] /usr/sbin/mysqld: Shutdown complete
140406 01:47:27 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Could someone please tell me what is going on?
Thanks
Looks you have a mysql process running. There's a lock on your ./ibdata1 file. it could be that for some reason your service mysql stop command is not stopping the process as it may not be finding the PID of your mysql server.
Run from the command line:
ps -Af | grep mysql
Get the PID of your mysql process and then simply:
kill -9 <PID of your mysql process>
cd /var/lib/mysql
#killall -9 mysqld
#innochecksum -d ibdata1
nano /etc/mysql/my.cnf
[mysqld]
innodb_force_recovery = 4
/etc/init.d/mysql start