Recovering MySQL Database From Data Directories - mysql

I am trying to recover a MySQL database from data directories. I do have a backup, but it is a week old and I would prefer not to use it.
I have transferred all of the files to a fresh MySQL installation and have given them 777 permissions along with directory and group ownership to mysql.
When I try to start, I get the following two errors:
InnoDB: Error: log file ./ib_logfile0 is of different size 0 0 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!
and
170110 16:42:58 [ERROR] Plugin 'InnoDB' init function returned error.
170110 16:42:58 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
For the first error, I have tried specifying the log file size in the my.cnf and also as an argument to mysqld. I keep getting the same error message.
For the second error, I have tried deleting the ib_logfile0 and ib_logfile1, but if I do, I get a bunch of nonsensical characters when starting mysqld followed by
/usr/sbin/mysqld(+0x286668)[0x7f65298d4668]
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.
How can I retrieve the data in this database?

Related

MAMP4 not launching MySQL

Downloaded MAMP4 and installed over MAMP1.9.4 (I know, it's old) with Mac OSX Sierra. Apache server launches, but not MySQL. Warned that previous db was copied to a folder named mysql56 and that on starting up MySQL need to convert db. But MySQL doesn't even start up! Activity Monitor shows no other mysql process going on. MAMP error log:
2017-01-16 12:35:13 47394 [ERROR] InnoDB: auto-extending data file ./ibdata1 is of a different size 640 pages (rounded down to MB) than specified in the .cnf file: initial 768 pages, max 0 (relevant if non-zero) pages!
2017-01-16 12:35:13 47394 [ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!
2017-01-16 12:35:13 47394 [ERROR] Plugin 'InnoDB' init function returned error.
2017-01-16 12:35:13 47394 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2017-01-16 12:35:13 47394 [ERROR] Unknown/unsupported storage engine: InnoDB
2017-01-16 12:35:13 47394 [ERROR] Aborting
I tried using the same ports as I used with MAMP1.9.4 (80 & 3306), then switched to default. Webserver address was pointing to my directory where I keep my websites. Changed it back to Applications/MAMP/htdocs. Nothing is working. :( Any help would be very much appreciated.
Oh, on my old machine running Snow Leopard, it's all still working with MAMP1.9.4.
Found the solution at http://rat32.com/rat32/2016/11/29/how-to-solve-mysql-not-starting-in-mamp-problem/#comment-175889. Removed all files except folders from Applications/MAMP/db/mysql56. Then restarted. MAMP immediately connected to the MySQL server and prompted me to upgrade my databases. All is well.
I tried other suggestions. The most common was to check for any other MySQL processes that might be running and to kill them via Terminal command. Another suggestion was to rename the files ib_logfile0 and ib_logfile1 in /Library/Application Support/MAMP PRO/db/mysql56, but as I had not initiated MAMP PRO, that folder did not exist. I had renamed the two files in Applications/MAMP/db/mysql56, but that didn't solve the problem. Only when I actually removed those two files and a third, then MAMP was able to connect to the MySQL server.
So it seems silly to answer my own question, but just want to put it here in case others run into the same problem.
Using MAMP 4.1 with Mac OSX Sierra.

DataBase Error InnoDB: cannot calculate statistics for table

While checking the error logs in my wordpress site I would get the following for the mysql logs.
161120 6:41:58 InnoDB: cannot calculate statistics for table databasename/wp_wfHoover
InnoDB: because the .ibd file is missing. For help, please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/innodb-troubleshooting.html
161120 6:41:58 [ERROR] MySQL is trying to open a table handle but the .ibd file for
table databasename/wp_wfHoover does not exist.
Have you deleted the .ibd file from the database directory under
the MySQL datadir, or have you used DISCARD TABLESPACE?
See http://dev.mysql.com/doc/refman/5.5/en/innodb-troubleshooting.html
What is the problem here? My site is hosted on an ubuntu server using apache2.Thanks in advance

XAMPP: MYSQL stops working after I restart

I am having problems with starting MYSQL in XAMPP. Apache starts alright but then MYSQL keeps reporting an unexpected shutdown.
I was led to delete C:\xampp\mysql\data\ibdata1 and it works after that but that deletes all my databases and MYSQL stops working again after I restart my machine.
I went through the error logs and this is what I saw:
[ERROR] InnoDB: Attempted to open a previously opened tablespace.
Previous tablespace mysql/innodb_index_stats uses space ID: 2 at
filepath: .\mysql\innodb_index_stats.ibd. Cannot open tablespace
yiicrud/customer which uses space ID: 2 at filepath:
.\yiicrud\customer.ibd InnoDB: Error: could not open single-table
tablespace file .\yiicrud\customer.ibd InnoDB: We do not continue the
crash recovery, because the table may become InnoDB: corrupt if we
cannot apply the log records in the InnoDB log to it. InnoDB: To fix
the problem and start mysqld: InnoDB: 1) If there is a permission
problem in the file and mysqld cannot InnoDB: open the file, you
should modify the permissions. InnoDB: 2) If the table is not needed,
or you can restore it from a backup, InnoDB: then you can remove the
.ibd file, and InnoDB will do a normal InnoDB: crash recovery and
ignore that table. InnoDB: 3) If the file system or the disk is
broken, and you cannot remove InnoDB: the .ibd file, you can set
innodb_force_recovery > 0 in my.cnf InnoDB: and force InnoDB to
continue crash recovery here.
Adding this line in my.cnf worked for me:
innodb_force_recovery = 1
There is a solution on this page: XAMPP/MySQL: could not open single-table tablespace file .\mysql\innodb_index_stats.ibd after restart of MySQL
Move (DON'T DELETE) those files, into another folder:
innodb_index_stats.frm <br>
innodb_table_stats.frm <br>
slave_worker_info.frm <br>
slave_master_info.frm <br>
slave_relay_log_info.frm <br>
and .ibd files with the same filename.
Try start MySQL.
Thanks a lot everyone.
I have able to solve it. It appears the database was created in a later version and was incompatible with this new version of xampp so i created the databases again and imported the tables into them. Previously I was importing the database with the create statements as well.
Had the idea from Salman's comment.
Try this
rename the XAMMP\mysql\data folder to any other name you wish (say data_old )
make a new folder in XAMMP\mysql name data and copy all the files in it including ibdata1
close all running programs and restart XAMPP
No need to copy files from data_old but if you do have previously constructed databases then you may copy some files from data_old.
The solution may come again. If it then you have to change the port to something else like 3308 in the config settings as well as in phpMyAdmin/config.inc.php.
If the problem stays still then its better to change the application which uses the port 3306 and set default settings in XAMPP.

Cannot start MySql server

I have problem starting the MySql server.
The log says:
InnoDB: Error in opening ./ibdata1
111220 16:16:43 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.0/en/operating-system-error-codes.html
InnoDB: Could not open or create data files.
InnoDB: If you tried to add new data files, and it failed here,
InnoDB: you should now edit innodb_data_file_path in my.cnf back
InnoDB: to what it was, and remove the new ibdata files InnoDB created
InnoDB: in this failed attempt. InnoDB only wrote those files full of
InnoDB: zeros, but did not yet use them in any way. But be careful: do not
InnoDB: remove old data files which contain your precious data!
/usr/libexec/mysqld: Disk is full writing './mysql-bin.000028' (Errcode: 28). Waiting for someone to free space... Retry
in 60 secs
After I check the disk - it says it's full.
So, after searching for solution - I found that I need to purge the binary log.
However, in order to purge - I need to start the MySql server, but all the spacein the disk is taken by the binary log, so I can't start...
It's also not advised to simply delete the binary logs.
So, I am kind of stuck.
Can't run the mysql to purge logs and can't purge logs because can't run server.
Any help? :)
Edit: The disk contains only the logs, there's nothing else.
If the disk is ext[2|3|4] you can use tune2fs to set the portion of the disk reserved for root to 0, giving you maybe enough breathing room to start the server
this would be tune2fs -m 0 /dev/whatever (after unmounting, ofcourse)
Try to start the mysql server with the option --expire_logs_days=, it should delete the log and older than days directory at startup.
bye
Gianluca

mysql backup and restore from ib_logfile failure

Here's the case:
After computer being hacked, we are in a rush to backup all data out to other computer.
As a result, the mysql databases are not backup out as sql statement.
What we have done is backup out all the physical files/folders in the C drive to new computer.
Eg:
C:\Program Files\MySQL\MySQL Server 4.1\data
In this case, all data for mysql are inside unreadable file.
Inside data folder consist of files like ib_logfile0, ib_logfile1, but not ib_data1
All database's table structure format are inside each respective folder. (Some folder have .frm, .opt) (some other folder have .frm, .myd, .myi)
How can I retrieve back the data from the database in a new computer?
I tried to install the same mysql version(4.1) at new computer, then replace all backup files inside data folder into this mysql in new computer. Then restart mysql service.
When I restart, it fail: Could not start mysql service on local computer. error 1067: process terminated unexpectedly.
Error log showing:
InnoDB: The first specified data file .\ibdata1 did not exist:
InnoDB: a new database to be created!
090930 10:24:49 InnoDB: Setting file .\ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Error: log file .\ib_logfile0 is of different size 0 87031808 bytes
InnoDB: than specified in the .cnf file 0 25165824 bytes!
090930 10:24:49 [ERROR] Can't init databases
090930 10:24:49 [ERROR] Aborting
090930 10:24:49 [Note] C:\Program Files\MySQL\MySQL Server 4.1\bin\mysqld-nt: Shutdown complete
your error log indicates that your innodb configuration does not match your innodb files. you need to look at the configuration file on your old server to figure out where mysql was configured to store your innodb files. then go find those files and copy them to the new server. you should also copy the innodb configuration settings exactly from the old server and apply them to the new server.
you need to look at the mysql.err log in the data folder to see what's wrong.
did the mysql service start properly when you first installed it?
looks like you're on windows, so i'm going to guess that you moved the files instead of copying them. when you move files in windows, they retain their permissions. when you copy, they inherit the permissions from the folder. so check to make sure they have the right permissions.
Sounds like your innodb_log_file_size in my.ini was not the same as before.
Have a look a the ib_logfile0 filesize in the data folder and if it's 102,400KB it should be:
innodb_log_file_size=100M
Yours looks like it should be:
innodb_log_file_size=83M
(set to 24M now)
I've had this issue when someone used the installer to "repair" a mysql installation.
Have Fun.