mysql backup and restore from ib_logfile failure - mysql

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.

Related

Error: MySQL shutdown unexpectedly This may be due to a blocked port, missing dependencies [duplicate]

When I open XAMPP and click start MySQL button and it gives me an error.
I had started it just before, but now it isn't working.
12:19:12 PM [mysql] Attempting to start MySQL app...
12:19:12 PM [mysql] Status change detected: running
12:19:13 PM [mysql] Status change detected: stopped
12:19:13 PM [mysql] Error: MySQL shutdown unexpectedly.
12:19:13 PM [mysql] This may be due to a blocked port, missing dependencies,
12:19:13 PM [mysql] improper privileges, a crash, or a shutdown by another method
12:19:13 PM [mysql] Press the Logs button to view error logs and check
12:19:13 PM [mysql] the Windows Event Viewer for more clues
12:19:13 PM [mysql] If you need more help, copy and post this
12:19:13 PM [mysql] entire log window on the forums
Here is the contents of the error log:
2013-08-02 12:19:12 4536 [Note] Plugin 'FEDERATED' is disabled.
2013-08-02 12:19:12 f64 InnoDB: Warning: Using innodb_additional_mem_pool_size is DEPRECATED. This option may be removed in future releases, together with the option innodb_use_sys_malloc and with the InnoDB's internal memory allocator.
2013-08-02 12:19:12 4536 [Note] InnoDB: The InnoDB memory heap is disabled
2013-08-02 12:19:12 4536 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
2013-08-02 12:19:12 4536 [Note] InnoDB: Compressed tables use zlib 1.2.3
2013-08-02 12:19:12 4536 [Note] InnoDB: Not using CPU crc32 instructions
2013-08-02 12:19:12 4536 [Note] InnoDB: Initializing buffer pool, size = 16.0M
2013-08-02 12:19:12 4536 [Note] InnoDB: Completed initialization of buffer pool
2013-08-02 12:19:12 4536 [Note] InnoDB: Highest supported file format is Barracuda.
2013-08-02 12:19:12 4536 [Note] InnoDB: The log sequence numbers 0 and 0 in ibdata files do not match the log sequence number 1616798 in the ib_logfiles!
2013-08-02 12:19:12 4536 [Note] InnoDB: Database was not shutdown normally!
2013-08-02 12:19:12 4536 [Note] InnoDB: Starting crash recovery.
2013-08-02 12:19:12 4536 [Note] InnoDB: Reading tablespace information from the .ibd files...
The most important error message is here:
2013-08-02 12:19:12 4536 [ERROR] InnoDB:
Attempted to open a previously opened tablespace.
Previous tablespace mysql/innodb_table_stats uses space ID: 1 at filepath: .\mysql\innodb_table_stats.ibd.
Cannot open tablespace xat/payments which uses space ID: 1 at filepath: .\xat\payments.ibd
The rest of the log:
InnoDB: Error: could not open single-table tablespace file .\xat\payments.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.
What is the cause of these errors and how can I rectify them?
IMPORTANT: do NOT delete ibdata1 file. You could destroy all your databases.
Instead, first try using the MySQL backup folder which is included with XAMPP. So do next steps:
Rename folder mysql/data to mysql/data_old
Make a copy of mysql/backup folder and name it as mysql/data
Copy all your database folders from mysql/data_old into mysql/data (except mysql, performance_schema, and phpmyadmin folders)
Copy mysql/data_old/ibdata1 file into mysql/data folder
Start MySQL from XAMPP control panel
And, voilà!
EDIT (January 7th 2023)
As mentioned by some users, this is an emergency solution, not a permanent one. After recovering your data is strongly recommended to back it up, and reinstalling XAMPP, because the failure is related to a malfunction from some of the files of XAMPP, not the databases.
IMPORTANT Deleting this file may render any existing MySQL data unusable. Use with caution
Hey I just did this and it worked:
exit Xampp server
go to your C:\xampp\mysql\data directory
delete the ibdata1 file
restart xampp server
It should work
Jun 2022
Disclaimer
Although many people said 'it worked' and very few say 'it didn't'.
It is hard to say what could be the cause and it is not working. Personally, the solution provided below worked for me and I didn't get any issues so far hence I am sharing this.
I don't suggest uninstalling, so you can basically back up the file and try this solution. If it doesn't work then place those files again.
Worked on other Versions
This issue works on other xampp versions too.
I have not tested personally, but some users have.
( If you have tested on a different version, let me know in the comment, I will add it here)
XAMPP v8.1.6 - Saeid Z
XAMPP v7.4.16 - CapelliC
XAMPP v3.3.0 - Myself
Feb 2022 (Problem)
I had the same problem today (2 feb 2022).
I fixed this using the same solution I mentioned below (See Dec 2021 (Solution))
XAMPP Issue Screenshot
XAMPP Fixed
Dec 2021 (Solution)
Since this question is active continuously,
I will try my best to solve it.
My issue
I visit this post every time this issue happens. The only thing I tried was that I uninstalled xampp and reinstalled it, which fixed the problem. That was on my old system.
I am using windows 10 brand new with no unwanted software or issues, and I got this unexpected shutdown again after a long time. I came to this question, hoping someone would tell me actually what was going on instead of fixing these issues. But unfortunately, I could not find it.
Just to clarify, my new issue is not with
port
unexpected shutdown
windows stuck
unwanted software
virus or malware.
One day I turned on xampp, and it stops working.
Method 1 (22 Dec 2021)
Stop MySQL.
Go to the C:/xampp/mysql directory and copy the data folder and keep it somewhere else (probably in another drive) as a backup.
Go to your original data folder (C:/xampp/mysql) and sort the files by 'Type.'
Select the files that have the type INFO File and delete them (screenshot below).
Start MySQL. It should work now.
Method 1 Screenshot
Important
Not necessarily the solution above will always fix the issue. Sometimes it will not. To avoid the major risk of losing the data, try these.
Turn on MySQL in the Control Panel ONLY IF NEEDED.
DO NOT set the XAMPP Control Panel to turn it on windows startup.
Back up DB whenever possible. If not try to back up every weekend.
PS: I will try to update this answer whenever the above method(s) don't work. I will try to explain it in the simplest way possible without uninstalling XAMPP.
Let me know if it works for you.
If the answers mentioned above are not working, you can try deleting all the files in data, except for the folder
Goto:
C:\xampp\mysql\data
After that:
Goto: C:\xampp\mysql\bin
then open with notepad my.ini
, Its look like this.
Then delete or put into comment the port 3306 and change it to 8111 then run xamp with administrator and its work well.
Go to mysql/data/
Delete all random files (except the actual database folders)
Restart Apache and MySQL.
It should fix it.
WORKING SOLUTION :- Follow the below listed steps.
Step 1. Rename the folder c:\xampp\mysql\data to c:\xampp\mysql\data_bkp (you can use any name).
Step 2. Create a new folder c:\xampp\mysql\data.
Step 3. Copy the content that resides in mysql\backup to the new mysql\data folder.
Step 4. Copy all your database folders that are in mysql\data_bkp to mysql\data (skipping the mysql, performance_schema, and phpmyadmin folders from mysql\data_bkp).
IMPORTATN NOTE :- Please do not replace the existing files while pasting(click skip these files)
Step 5. Finally copy the ibdata1 file from mysql\data_bkp and replace it inside mysql\data folder.
Step 6. Start MySQL from XAMPP control panel.
And, Its DONE . No databases lost, no ports changed, no run as administrator, no force recovery, no kill mysqld process, no restoring from previous versions, no more errors.
Just follow two steps
go to xampp\mysql\backup
copy everything from backup folder
go to xampp\mysql\data
paste everything in data folder copied from backup folder
Thats all.
Also follow the video description to fix without losing any data:
https://www.youtube.com/watch?v=hB1wshpP3Jc
Or follow the article description to fix without losing any data:
https://webjourney.dev/error-mysql-shutdown-unexpectedly-solve-without-loosing-any-data-webjourney
UPDATE APRIL (2022)
Rename folder mysql/data to mysql/data_old
Make a copy of mysql/backup folder and name it as mysql/data
Copy all your database folders and mysql folder from mysql/data_old into mysql/data
Copy mysql/data_old/ibdata1 file into mysql/data folder
Start MySQL from XAMPP control panel
REFERENCE
https://www.youtube.com/watch?v=ipMedkjMupw&ab_channel=GeekyScript
When you're not running XAMPP as an administrator, shutting down MySQL frequently causes corruption which means you have to repair or delete your tables. To avoid this you need to either run XAMPP as an administrator, or use the proper command prompt method for shutting down MySQL.
You can delete ibdata1 as Kratos suggests, but this can leave you with a broken database as other pieces of your database are still in the /mysql/data/ folder. In my case, this residual data stopped me successfully installing WordPress.
A cleaner way of undoing the damage is to revert your whole /mysql/data/ folder. Windows has built-in folder versioning — right click on /mysql/data/ and select Restore previous versions. You can then delete the current contents of the folder and replace it with the older version's contents.
Addendum: To ensure that you don't forget to run XAMPP as an administrator you can right click the XAMPP shortcut, go to Properties, then Advanced, and finally tick Run as administrator.
I got the same kind of error in my C:\xampp\mysql\data\mysql_error.log when trying to start mysql.
2013-08-05 01:20:32 6780 [ERROR] InnoDB: Attempted to open a previously
opened tablespace. Previous tablespace mysql/slave_relay_log_info uses
space ID: 3 at filepath: .\mysql\slave_relay_log_info.ibd. Cannot open
tablespace test_database/test_table which uses space ID: 3 at filepath:
.\test_database\test_table.ibd
You'll have to read the error closely. This says that test_database is preventing mysql from starting.
You could blow away the offending database, these steps fix the problem:
Make sure mysql and xampp is shut down completely.
Go to your directory where mysql is installed, mine is: C:\xampp\mysql\data
You should see a folder with the name of a database that you created. mine was test_database.
Create a new folder somewhere else called C:\xampp\mysql\data\mysql\backuptablespace
Drag and drop (don't delete) the offending database table folder to the backup directory.
Try to start mysql again. For me it started right up in 1 second as expected.
If it doesn't work, put the file back where you started and you'll be back where you started.
If you don't want to delete the database and don't have backups:
If you don't have backups of table data and mysql won't start because something is corrupted you'll have to use the process of elimination to guess-and-check your way to exactly what you did that corrupted it. Follow these steps:
Make a clone of the entire C:\xampp\ and store it somewhere safe so you can get back to where you started.
Use a "binary search" approach to try to locate the corrupted item in the mysql database. It could be a file, or a table, or a database, or a user or anything.
Delete the entire database and see if that allows mysql to start. If it does, then put back the database and try removing some of the tables. If it doesn't, then try yanking out something else until it does start.
Try removing these files from C:\xampp\mysql\data\mysql:
db.frm
db.MRD
db.MYI
db.opt
user.frm
user.MYD
user.MYI
When you get mysql to start, try putting things back until you find the one thing that you add which prevents it from starting. One bonus for this is you learn how mysql works under the hood.
Nuclear option:
Something you did screwed up the mysql server. An uninstall and reinstall of XAMPP should undo the corruption.
Add the following line below the [mysqld] section in the mysql config file (my.ini) and restart the apache web server and the mysql service afterwards.
[mysqld]
innodb_force_recovery = 4
My Xampp MySQL worked just follows as below:
01.Go to mysql/data/ directory
02. delete the ibdata1 & ib_logfile*(ib_logfile0,ib_logfile1,ib_logfile101) file
03. restart xampp server
Step 1 : Close Xampp controller completely
Step 2 : Open C:\xampp\mysql\backup
Step 3 : Copy all the files from backup folder
Step 4 : Open C:\xampp\mysql\data
Step 5 : Paste the all the files in data folder
Step 6 : Re-start the Xampp controller
Never delete this file (ibdata1) because all your data will be deleted!!!
I suggest three ways :
A:
1- Exit from XAMPP control panel.
1- Rename the folder mysql/data to mysql/data_old (you can use any name)
2- Create a new folder mysql/data
3- Copy the content that resides in mysql/backup to the new mysql/data folder
4- Copy all your database folders that are in mysql/data_old to mysql/data (skipping the mysql, performance_schema, and phpmyadmin folders from data_old)
5- Finally copy the ibdata1 file from mysql/data_old and replace it inside mysql/data folder
6- Reastart your system.
B:
1- Stop all sql services.
2- Next, start all sql services again.
C:
1- Open XAMPP control panel
2- Click on Config button, in front of mysql, click on my.ini
3- change client port and server port.
I have tried all the above answers but it didn't work for me. So finally I tried the below approach and it works 100% for me.
If you are worried about following the below steps you can take a backup of the entire XAMPP folder for the safe side.
Step 1: Rename the c:\xampp\mysql\data folder to c:\xampp\mysql\data_bkp
Step 2: Create a new folder c:\xampp\mysql\data.
Step 3: Copy the content, that is present inside c:\xampp\mysql\backup to the new c:\xampp\mysql\data folder.
Step 4: Copy all your database folders c:\xampp\mysql\data_bkp to c:\xampp\mysql\data (Note: Don't copy mysql, performance_schema, and phpmyadmin folders).
Step 5: Copy the ibdata1 file from c:\xampp\mysql\data_bkp and replace it inside the c:\xampp\mysql\data folder.
Step 6: Start MySQL from the XAMPP control panel.
I also faced this issue and this is how I solved.
1. Make sure xampp is not under sub-directory. For example, it should be C:\xampp
2. You might need to run as administrator in running the application.
Hope this will work!
in my case i did following steps and it worked:
In Xampp control panel click on "Services" button from the right side toolbar
Then find "MySQL" from the services List
Click on it and from the left side of the panel click on "stop"
Turn back in Xampp control panel and click on start.
move xampp/mysql/backup files into xampp/mysql/data
RUN XAMPP as Administrator(make sure mysql is installed you can see a green tick if is installed)
Hope it helps!
Simple solution
Open shell from Xampp Control Panel
mysqld --console --skip-grant-tables --skip-external-locking
Then again open an other shell and run
mysqlcheck -r --databases mysql --use-frm
Now close both shells and restart the xampp.
I have resolved the problem by ending the task for mysqlid on Task Manager.
Here is the way you can solve this problem:
Go to C:\xampp\mysql\data
You will see a folder named as mysql/data
Rename that folder from mysql/data to something else like mysql/data_not_useful any name that you want to give.
Create a new folder named as mysql/data.
Copy all the files of the mysql/backup and paste in mysql/data.
Now go to mysql/data_not_useful and copy the file ibdata1 from there.
Then paste it in mysql/data (You have to replace the file).
Restart your xampp server.
Now run your mysql server.
Here is what I did. I restarted my computer. Next I run services.msc. I stopped the MySQL service then restarted it. The restarted the Xampp server.
No solution above worked for me. then I did below:
I deleted all the files inside C:\xampp\mysql\data\ directory except folders in this directory.
It worked perfectly fine but my previous databases are not working now.
So do above if you don't care it will delete all your previous databases in phpmyadmin.
i was facing the same issue and none of the solutions stated above helped me.
i went to the mysql configuration file (my.ini) and changed the port number under [mysqld].By default mysql runs on 3306 port.
port= 3306
i changed it to ,
port= 8111
Then run as Administrator.Finally this worked for me.
This means that you already have a MySQL database running at port 3306.
In the XAMPP control panel, press the 'Config' button and after that press 'my.ini'. After this, Ctrl-F and search for '3306'. Replace any '3306' that you find with a different port number of your choice (you could choose 3307 or 3308 - I chose 2811 and it worked).
After you have replaced every location where '3306' is written, save the file and press 'Start' on the control panel again.
Had the same issue.
STAEP 1
backup folder xampp/mysql/data (saved it as `xampp/mysql/_old_data`).
STAEP 2
Go to xampp/mysql/data and deleted all the files but not folders! With databases.
STAEP 3
At this stage your database will not work. You need to go to your backup folder `xampp/mysql/_old_data` and copy over "`ibdata1`" file to `xampp/mysql/data`.
After that everything work as expected including phpmyadmin and console.
STAEP 4
If this does not help. You can remove xampp/mysql/data folder and rename xampp/mysql/_old_data back to xampp/mysql/data.
(ROLLBACK) and try different things.
Xampp stop Instantly after start.
copy all files and folder from C:\xampp\mysql\backup and paste into
C:\xampp\mysql\data.
Go to xampp/mysql/data
Rename folder from data to data_backup
Create new folder data
Copy files from backup to data
delete ibdata1 from data folder
Copy ibdata1 from data_backup folder to data folder
Copy your all database from data_backup to data folder
Restart xampp. It will start working
Copy all files from xampp/mysql/backup/ then paste into /xampp/mysql/data/
Restart mysql.
0.cntr+alt+delet
1.end task mysqld
2.Restart mysql.

XAMPP MySQL cannot start [duplicate]

When I open XAMPP and click start MySQL button and it gives me an error.
I had started it just before, but now it isn't working.
12:19:12 PM [mysql] Attempting to start MySQL app...
12:19:12 PM [mysql] Status change detected: running
12:19:13 PM [mysql] Status change detected: stopped
12:19:13 PM [mysql] Error: MySQL shutdown unexpectedly.
12:19:13 PM [mysql] This may be due to a blocked port, missing dependencies,
12:19:13 PM [mysql] improper privileges, a crash, or a shutdown by another method
12:19:13 PM [mysql] Press the Logs button to view error logs and check
12:19:13 PM [mysql] the Windows Event Viewer for more clues
12:19:13 PM [mysql] If you need more help, copy and post this
12:19:13 PM [mysql] entire log window on the forums
Here is the contents of the error log:
2013-08-02 12:19:12 4536 [Note] Plugin 'FEDERATED' is disabled.
2013-08-02 12:19:12 f64 InnoDB: Warning: Using innodb_additional_mem_pool_size is DEPRECATED. This option may be removed in future releases, together with the option innodb_use_sys_malloc and with the InnoDB's internal memory allocator.
2013-08-02 12:19:12 4536 [Note] InnoDB: The InnoDB memory heap is disabled
2013-08-02 12:19:12 4536 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
2013-08-02 12:19:12 4536 [Note] InnoDB: Compressed tables use zlib 1.2.3
2013-08-02 12:19:12 4536 [Note] InnoDB: Not using CPU crc32 instructions
2013-08-02 12:19:12 4536 [Note] InnoDB: Initializing buffer pool, size = 16.0M
2013-08-02 12:19:12 4536 [Note] InnoDB: Completed initialization of buffer pool
2013-08-02 12:19:12 4536 [Note] InnoDB: Highest supported file format is Barracuda.
2013-08-02 12:19:12 4536 [Note] InnoDB: The log sequence numbers 0 and 0 in ibdata files do not match the log sequence number 1616798 in the ib_logfiles!
2013-08-02 12:19:12 4536 [Note] InnoDB: Database was not shutdown normally!
2013-08-02 12:19:12 4536 [Note] InnoDB: Starting crash recovery.
2013-08-02 12:19:12 4536 [Note] InnoDB: Reading tablespace information from the .ibd files...
The most important error message is here:
2013-08-02 12:19:12 4536 [ERROR] InnoDB:
Attempted to open a previously opened tablespace.
Previous tablespace mysql/innodb_table_stats uses space ID: 1 at filepath: .\mysql\innodb_table_stats.ibd.
Cannot open tablespace xat/payments which uses space ID: 1 at filepath: .\xat\payments.ibd
The rest of the log:
InnoDB: Error: could not open single-table tablespace file .\xat\payments.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.
What is the cause of these errors and how can I rectify them?
IMPORTANT: do NOT delete ibdata1 file. You could destroy all your databases.
Instead, first try using the MySQL backup folder which is included with XAMPP. So do next steps:
Rename folder mysql/data to mysql/data_old
Make a copy of mysql/backup folder and name it as mysql/data
Copy all your database folders from mysql/data_old into mysql/data (except mysql, performance_schema, and phpmyadmin folders)
Copy mysql/data_old/ibdata1 file into mysql/data folder
Start MySQL from XAMPP control panel
And, voilà!
EDIT (January 7th 2023)
As mentioned by some users, this is an emergency solution, not a permanent one. After recovering your data is strongly recommended to back it up, and reinstalling XAMPP, because the failure is related to a malfunction from some of the files of XAMPP, not the databases.
IMPORTANT Deleting this file may render any existing MySQL data unusable. Use with caution
Hey I just did this and it worked:
exit Xampp server
go to your C:\xampp\mysql\data directory
delete the ibdata1 file
restart xampp server
It should work
Jun 2022
Disclaimer
Although many people said 'it worked' and very few say 'it didn't'.
It is hard to say what could be the cause and it is not working. Personally, the solution provided below worked for me and I didn't get any issues so far hence I am sharing this.
I don't suggest uninstalling, so you can basically back up the file and try this solution. If it doesn't work then place those files again.
Worked on other Versions
This issue works on other xampp versions too.
I have not tested personally, but some users have.
( If you have tested on a different version, let me know in the comment, I will add it here)
XAMPP v8.1.6 - Saeid Z
XAMPP v7.4.16 - CapelliC
XAMPP v3.3.0 - Myself
Feb 2022 (Problem)
I had the same problem today (2 feb 2022).
I fixed this using the same solution I mentioned below (See Dec 2021 (Solution))
XAMPP Issue Screenshot
XAMPP Fixed
Dec 2021 (Solution)
Since this question is active continuously,
I will try my best to solve it.
My issue
I visit this post every time this issue happens. The only thing I tried was that I uninstalled xampp and reinstalled it, which fixed the problem. That was on my old system.
I am using windows 10 brand new with no unwanted software or issues, and I got this unexpected shutdown again after a long time. I came to this question, hoping someone would tell me actually what was going on instead of fixing these issues. But unfortunately, I could not find it.
Just to clarify, my new issue is not with
port
unexpected shutdown
windows stuck
unwanted software
virus or malware.
One day I turned on xampp, and it stops working.
Method 1 (22 Dec 2021)
Stop MySQL.
Go to the C:/xampp/mysql directory and copy the data folder and keep it somewhere else (probably in another drive) as a backup.
Go to your original data folder (C:/xampp/mysql) and sort the files by 'Type.'
Select the files that have the type INFO File and delete them (screenshot below).
Start MySQL. It should work now.
Method 1 Screenshot
Important
Not necessarily the solution above will always fix the issue. Sometimes it will not. To avoid the major risk of losing the data, try these.
Turn on MySQL in the Control Panel ONLY IF NEEDED.
DO NOT set the XAMPP Control Panel to turn it on windows startup.
Back up DB whenever possible. If not try to back up every weekend.
PS: I will try to update this answer whenever the above method(s) don't work. I will try to explain it in the simplest way possible without uninstalling XAMPP.
Let me know if it works for you.
If the answers mentioned above are not working, you can try deleting all the files in data, except for the folder
Goto:
C:\xampp\mysql\data
After that:
Goto: C:\xampp\mysql\bin
then open with notepad my.ini
, Its look like this.
Then delete or put into comment the port 3306 and change it to 8111 then run xamp with administrator and its work well.
Go to mysql/data/
Delete all random files (except the actual database folders)
Restart Apache and MySQL.
It should fix it.
WORKING SOLUTION :- Follow the below listed steps.
Step 1. Rename the folder c:\xampp\mysql\data to c:\xampp\mysql\data_bkp (you can use any name).
Step 2. Create a new folder c:\xampp\mysql\data.
Step 3. Copy the content that resides in mysql\backup to the new mysql\data folder.
Step 4. Copy all your database folders that are in mysql\data_bkp to mysql\data (skipping the mysql, performance_schema, and phpmyadmin folders from mysql\data_bkp).
IMPORTATN NOTE :- Please do not replace the existing files while pasting(click skip these files)
Step 5. Finally copy the ibdata1 file from mysql\data_bkp and replace it inside mysql\data folder.
Step 6. Start MySQL from XAMPP control panel.
And, Its DONE . No databases lost, no ports changed, no run as administrator, no force recovery, no kill mysqld process, no restoring from previous versions, no more errors.
Just follow two steps
go to xampp\mysql\backup
copy everything from backup folder
go to xampp\mysql\data
paste everything in data folder copied from backup folder
Thats all.
Also follow the video description to fix without losing any data:
https://www.youtube.com/watch?v=hB1wshpP3Jc
Or follow the article description to fix without losing any data:
https://webjourney.dev/error-mysql-shutdown-unexpectedly-solve-without-loosing-any-data-webjourney
UPDATE APRIL (2022)
Rename folder mysql/data to mysql/data_old
Make a copy of mysql/backup folder and name it as mysql/data
Copy all your database folders and mysql folder from mysql/data_old into mysql/data
Copy mysql/data_old/ibdata1 file into mysql/data folder
Start MySQL from XAMPP control panel
REFERENCE
https://www.youtube.com/watch?v=ipMedkjMupw&ab_channel=GeekyScript
When you're not running XAMPP as an administrator, shutting down MySQL frequently causes corruption which means you have to repair or delete your tables. To avoid this you need to either run XAMPP as an administrator, or use the proper command prompt method for shutting down MySQL.
You can delete ibdata1 as Kratos suggests, but this can leave you with a broken database as other pieces of your database are still in the /mysql/data/ folder. In my case, this residual data stopped me successfully installing WordPress.
A cleaner way of undoing the damage is to revert your whole /mysql/data/ folder. Windows has built-in folder versioning — right click on /mysql/data/ and select Restore previous versions. You can then delete the current contents of the folder and replace it with the older version's contents.
Addendum: To ensure that you don't forget to run XAMPP as an administrator you can right click the XAMPP shortcut, go to Properties, then Advanced, and finally tick Run as administrator.
I got the same kind of error in my C:\xampp\mysql\data\mysql_error.log when trying to start mysql.
2013-08-05 01:20:32 6780 [ERROR] InnoDB: Attempted to open a previously
opened tablespace. Previous tablespace mysql/slave_relay_log_info uses
space ID: 3 at filepath: .\mysql\slave_relay_log_info.ibd. Cannot open
tablespace test_database/test_table which uses space ID: 3 at filepath:
.\test_database\test_table.ibd
You'll have to read the error closely. This says that test_database is preventing mysql from starting.
You could blow away the offending database, these steps fix the problem:
Make sure mysql and xampp is shut down completely.
Go to your directory where mysql is installed, mine is: C:\xampp\mysql\data
You should see a folder with the name of a database that you created. mine was test_database.
Create a new folder somewhere else called C:\xampp\mysql\data\mysql\backuptablespace
Drag and drop (don't delete) the offending database table folder to the backup directory.
Try to start mysql again. For me it started right up in 1 second as expected.
If it doesn't work, put the file back where you started and you'll be back where you started.
If you don't want to delete the database and don't have backups:
If you don't have backups of table data and mysql won't start because something is corrupted you'll have to use the process of elimination to guess-and-check your way to exactly what you did that corrupted it. Follow these steps:
Make a clone of the entire C:\xampp\ and store it somewhere safe so you can get back to where you started.
Use a "binary search" approach to try to locate the corrupted item in the mysql database. It could be a file, or a table, or a database, or a user or anything.
Delete the entire database and see if that allows mysql to start. If it does, then put back the database and try removing some of the tables. If it doesn't, then try yanking out something else until it does start.
Try removing these files from C:\xampp\mysql\data\mysql:
db.frm
db.MRD
db.MYI
db.opt
user.frm
user.MYD
user.MYI
When you get mysql to start, try putting things back until you find the one thing that you add which prevents it from starting. One bonus for this is you learn how mysql works under the hood.
Nuclear option:
Something you did screwed up the mysql server. An uninstall and reinstall of XAMPP should undo the corruption.
Add the following line below the [mysqld] section in the mysql config file (my.ini) and restart the apache web server and the mysql service afterwards.
[mysqld]
innodb_force_recovery = 4
My Xampp MySQL worked just follows as below:
01.Go to mysql/data/ directory
02. delete the ibdata1 & ib_logfile*(ib_logfile0,ib_logfile1,ib_logfile101) file
03. restart xampp server
Step 1 : Close Xampp controller completely
Step 2 : Open C:\xampp\mysql\backup
Step 3 : Copy all the files from backup folder
Step 4 : Open C:\xampp\mysql\data
Step 5 : Paste the all the files in data folder
Step 6 : Re-start the Xampp controller
Never delete this file (ibdata1) because all your data will be deleted!!!
I suggest three ways :
A:
1- Exit from XAMPP control panel.
1- Rename the folder mysql/data to mysql/data_old (you can use any name)
2- Create a new folder mysql/data
3- Copy the content that resides in mysql/backup to the new mysql/data folder
4- Copy all your database folders that are in mysql/data_old to mysql/data (skipping the mysql, performance_schema, and phpmyadmin folders from data_old)
5- Finally copy the ibdata1 file from mysql/data_old and replace it inside mysql/data folder
6- Reastart your system.
B:
1- Stop all sql services.
2- Next, start all sql services again.
C:
1- Open XAMPP control panel
2- Click on Config button, in front of mysql, click on my.ini
3- change client port and server port.
I have tried all the above answers but it didn't work for me. So finally I tried the below approach and it works 100% for me.
If you are worried about following the below steps you can take a backup of the entire XAMPP folder for the safe side.
Step 1: Rename the c:\xampp\mysql\data folder to c:\xampp\mysql\data_bkp
Step 2: Create a new folder c:\xampp\mysql\data.
Step 3: Copy the content, that is present inside c:\xampp\mysql\backup to the new c:\xampp\mysql\data folder.
Step 4: Copy all your database folders c:\xampp\mysql\data_bkp to c:\xampp\mysql\data (Note: Don't copy mysql, performance_schema, and phpmyadmin folders).
Step 5: Copy the ibdata1 file from c:\xampp\mysql\data_bkp and replace it inside the c:\xampp\mysql\data folder.
Step 6: Start MySQL from the XAMPP control panel.
I also faced this issue and this is how I solved.
1. Make sure xampp is not under sub-directory. For example, it should be C:\xampp
2. You might need to run as administrator in running the application.
Hope this will work!
in my case i did following steps and it worked:
In Xampp control panel click on "Services" button from the right side toolbar
Then find "MySQL" from the services List
Click on it and from the left side of the panel click on "stop"
Turn back in Xampp control panel and click on start.
move xampp/mysql/backup files into xampp/mysql/data
RUN XAMPP as Administrator(make sure mysql is installed you can see a green tick if is installed)
Hope it helps!
Simple solution
Open shell from Xampp Control Panel
mysqld --console --skip-grant-tables --skip-external-locking
Then again open an other shell and run
mysqlcheck -r --databases mysql --use-frm
Now close both shells and restart the xampp.
I have resolved the problem by ending the task for mysqlid on Task Manager.
Here is the way you can solve this problem:
Go to C:\xampp\mysql\data
You will see a folder named as mysql/data
Rename that folder from mysql/data to something else like mysql/data_not_useful any name that you want to give.
Create a new folder named as mysql/data.
Copy all the files of the mysql/backup and paste in mysql/data.
Now go to mysql/data_not_useful and copy the file ibdata1 from there.
Then paste it in mysql/data (You have to replace the file).
Restart your xampp server.
Now run your mysql server.
Here is what I did. I restarted my computer. Next I run services.msc. I stopped the MySQL service then restarted it. The restarted the Xampp server.
No solution above worked for me. then I did below:
I deleted all the files inside C:\xampp\mysql\data\ directory except folders in this directory.
It worked perfectly fine but my previous databases are not working now.
So do above if you don't care it will delete all your previous databases in phpmyadmin.
i was facing the same issue and none of the solutions stated above helped me.
i went to the mysql configuration file (my.ini) and changed the port number under [mysqld].By default mysql runs on 3306 port.
port= 3306
i changed it to ,
port= 8111
Then run as Administrator.Finally this worked for me.
This means that you already have a MySQL database running at port 3306.
In the XAMPP control panel, press the 'Config' button and after that press 'my.ini'. After this, Ctrl-F and search for '3306'. Replace any '3306' that you find with a different port number of your choice (you could choose 3307 or 3308 - I chose 2811 and it worked).
After you have replaced every location where '3306' is written, save the file and press 'Start' on the control panel again.
Had the same issue.
STAEP 1
backup folder xampp/mysql/data (saved it as `xampp/mysql/_old_data`).
STAEP 2
Go to xampp/mysql/data and deleted all the files but not folders! With databases.
STAEP 3
At this stage your database will not work. You need to go to your backup folder `xampp/mysql/_old_data` and copy over "`ibdata1`" file to `xampp/mysql/data`.
After that everything work as expected including phpmyadmin and console.
STAEP 4
If this does not help. You can remove xampp/mysql/data folder and rename xampp/mysql/_old_data back to xampp/mysql/data.
(ROLLBACK) and try different things.
Xampp stop Instantly after start.
copy all files and folder from C:\xampp\mysql\backup and paste into
C:\xampp\mysql\data.
Go to xampp/mysql/data
Rename folder from data to data_backup
Create new folder data
Copy files from backup to data
delete ibdata1 from data folder
Copy ibdata1 from data_backup folder to data folder
Copy your all database from data_backup to data folder
Restart xampp. It will start working
Copy all files from xampp/mysql/backup/ then paste into /xampp/mysql/data/
Restart mysql.
0.cntr+alt+delet
1.end task mysqld
2.Restart mysql.

XAMPP : Error: MySQL shutdown unexpectedly [duplicate]

When I open XAMPP and click start MySQL button and it gives me an error.
I had started it just before, but now it isn't working.
12:19:12 PM [mysql] Attempting to start MySQL app...
12:19:12 PM [mysql] Status change detected: running
12:19:13 PM [mysql] Status change detected: stopped
12:19:13 PM [mysql] Error: MySQL shutdown unexpectedly.
12:19:13 PM [mysql] This may be due to a blocked port, missing dependencies,
12:19:13 PM [mysql] improper privileges, a crash, or a shutdown by another method
12:19:13 PM [mysql] Press the Logs button to view error logs and check
12:19:13 PM [mysql] the Windows Event Viewer for more clues
12:19:13 PM [mysql] If you need more help, copy and post this
12:19:13 PM [mysql] entire log window on the forums
Here is the contents of the error log:
2013-08-02 12:19:12 4536 [Note] Plugin 'FEDERATED' is disabled.
2013-08-02 12:19:12 f64 InnoDB: Warning: Using innodb_additional_mem_pool_size is DEPRECATED. This option may be removed in future releases, together with the option innodb_use_sys_malloc and with the InnoDB's internal memory allocator.
2013-08-02 12:19:12 4536 [Note] InnoDB: The InnoDB memory heap is disabled
2013-08-02 12:19:12 4536 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
2013-08-02 12:19:12 4536 [Note] InnoDB: Compressed tables use zlib 1.2.3
2013-08-02 12:19:12 4536 [Note] InnoDB: Not using CPU crc32 instructions
2013-08-02 12:19:12 4536 [Note] InnoDB: Initializing buffer pool, size = 16.0M
2013-08-02 12:19:12 4536 [Note] InnoDB: Completed initialization of buffer pool
2013-08-02 12:19:12 4536 [Note] InnoDB: Highest supported file format is Barracuda.
2013-08-02 12:19:12 4536 [Note] InnoDB: The log sequence numbers 0 and 0 in ibdata files do not match the log sequence number 1616798 in the ib_logfiles!
2013-08-02 12:19:12 4536 [Note] InnoDB: Database was not shutdown normally!
2013-08-02 12:19:12 4536 [Note] InnoDB: Starting crash recovery.
2013-08-02 12:19:12 4536 [Note] InnoDB: Reading tablespace information from the .ibd files...
The most important error message is here:
2013-08-02 12:19:12 4536 [ERROR] InnoDB:
Attempted to open a previously opened tablespace.
Previous tablespace mysql/innodb_table_stats uses space ID: 1 at filepath: .\mysql\innodb_table_stats.ibd.
Cannot open tablespace xat/payments which uses space ID: 1 at filepath: .\xat\payments.ibd
The rest of the log:
InnoDB: Error: could not open single-table tablespace file .\xat\payments.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.
What is the cause of these errors and how can I rectify them?
IMPORTANT: do NOT delete ibdata1 file. You could destroy all your databases.
Instead, first try using the MySQL backup folder which is included with XAMPP. So do next steps:
Rename folder mysql/data to mysql/data_old
Make a copy of mysql/backup folder and name it as mysql/data
Copy all your database folders from mysql/data_old into mysql/data (except mysql, performance_schema, and phpmyadmin folders)
Copy mysql/data_old/ibdata1 file into mysql/data folder
Start MySQL from XAMPP control panel
And, voilà!
EDIT (January 7th 2023)
As mentioned by some users, this is an emergency solution, not a permanent one. After recovering your data is strongly recommended to back it up, and reinstalling XAMPP, because the failure is related to a malfunction from some of the files of XAMPP, not the databases.
IMPORTANT Deleting this file may render any existing MySQL data unusable. Use with caution
Hey I just did this and it worked:
exit Xampp server
go to your C:\xampp\mysql\data directory
delete the ibdata1 file
restart xampp server
It should work
Jun 2022
Disclaimer
Although many people said 'it worked' and very few say 'it didn't'.
It is hard to say what could be the cause and it is not working. Personally, the solution provided below worked for me and I didn't get any issues so far hence I am sharing this.
I don't suggest uninstalling, so you can basically back up the file and try this solution. If it doesn't work then place those files again.
Worked on other Versions
This issue works on other xampp versions too.
I have not tested personally, but some users have.
( If you have tested on a different version, let me know in the comment, I will add it here)
XAMPP v8.1.6 - Saeid Z
XAMPP v7.4.16 - CapelliC
XAMPP v3.3.0 - Myself
Feb 2022 (Problem)
I had the same problem today (2 feb 2022).
I fixed this using the same solution I mentioned below (See Dec 2021 (Solution))
XAMPP Issue Screenshot
XAMPP Fixed
Dec 2021 (Solution)
Since this question is active continuously,
I will try my best to solve it.
My issue
I visit this post every time this issue happens. The only thing I tried was that I uninstalled xampp and reinstalled it, which fixed the problem. That was on my old system.
I am using windows 10 brand new with no unwanted software or issues, and I got this unexpected shutdown again after a long time. I came to this question, hoping someone would tell me actually what was going on instead of fixing these issues. But unfortunately, I could not find it.
Just to clarify, my new issue is not with
port
unexpected shutdown
windows stuck
unwanted software
virus or malware.
One day I turned on xampp, and it stops working.
Method 1 (22 Dec 2021)
Stop MySQL.
Go to the C:/xampp/mysql directory and copy the data folder and keep it somewhere else (probably in another drive) as a backup.
Go to your original data folder (C:/xampp/mysql) and sort the files by 'Type.'
Select the files that have the type INFO File and delete them (screenshot below).
Start MySQL. It should work now.
Method 1 Screenshot
Important
Not necessarily the solution above will always fix the issue. Sometimes it will not. To avoid the major risk of losing the data, try these.
Turn on MySQL in the Control Panel ONLY IF NEEDED.
DO NOT set the XAMPP Control Panel to turn it on windows startup.
Back up DB whenever possible. If not try to back up every weekend.
PS: I will try to update this answer whenever the above method(s) don't work. I will try to explain it in the simplest way possible without uninstalling XAMPP.
Let me know if it works for you.
If the answers mentioned above are not working, you can try deleting all the files in data, except for the folder
Goto:
C:\xampp\mysql\data
After that:
Goto: C:\xampp\mysql\bin
then open with notepad my.ini
, Its look like this.
Then delete or put into comment the port 3306 and change it to 8111 then run xamp with administrator and its work well.
Go to mysql/data/
Delete all random files (except the actual database folders)
Restart Apache and MySQL.
It should fix it.
WORKING SOLUTION :- Follow the below listed steps.
Step 1. Rename the folder c:\xampp\mysql\data to c:\xampp\mysql\data_bkp (you can use any name).
Step 2. Create a new folder c:\xampp\mysql\data.
Step 3. Copy the content that resides in mysql\backup to the new mysql\data folder.
Step 4. Copy all your database folders that are in mysql\data_bkp to mysql\data (skipping the mysql, performance_schema, and phpmyadmin folders from mysql\data_bkp).
IMPORTATN NOTE :- Please do not replace the existing files while pasting(click skip these files)
Step 5. Finally copy the ibdata1 file from mysql\data_bkp and replace it inside mysql\data folder.
Step 6. Start MySQL from XAMPP control panel.
And, Its DONE . No databases lost, no ports changed, no run as administrator, no force recovery, no kill mysqld process, no restoring from previous versions, no more errors.
Just follow two steps
go to xampp\mysql\backup
copy everything from backup folder
go to xampp\mysql\data
paste everything in data folder copied from backup folder
Thats all.
Also follow the video description to fix without losing any data:
https://www.youtube.com/watch?v=hB1wshpP3Jc
Or follow the article description to fix without losing any data:
https://webjourney.dev/error-mysql-shutdown-unexpectedly-solve-without-loosing-any-data-webjourney
UPDATE APRIL (2022)
Rename folder mysql/data to mysql/data_old
Make a copy of mysql/backup folder and name it as mysql/data
Copy all your database folders and mysql folder from mysql/data_old into mysql/data
Copy mysql/data_old/ibdata1 file into mysql/data folder
Start MySQL from XAMPP control panel
REFERENCE
https://www.youtube.com/watch?v=ipMedkjMupw&ab_channel=GeekyScript
When you're not running XAMPP as an administrator, shutting down MySQL frequently causes corruption which means you have to repair or delete your tables. To avoid this you need to either run XAMPP as an administrator, or use the proper command prompt method for shutting down MySQL.
You can delete ibdata1 as Kratos suggests, but this can leave you with a broken database as other pieces of your database are still in the /mysql/data/ folder. In my case, this residual data stopped me successfully installing WordPress.
A cleaner way of undoing the damage is to revert your whole /mysql/data/ folder. Windows has built-in folder versioning — right click on /mysql/data/ and select Restore previous versions. You can then delete the current contents of the folder and replace it with the older version's contents.
Addendum: To ensure that you don't forget to run XAMPP as an administrator you can right click the XAMPP shortcut, go to Properties, then Advanced, and finally tick Run as administrator.
I got the same kind of error in my C:\xampp\mysql\data\mysql_error.log when trying to start mysql.
2013-08-05 01:20:32 6780 [ERROR] InnoDB: Attempted to open a previously
opened tablespace. Previous tablespace mysql/slave_relay_log_info uses
space ID: 3 at filepath: .\mysql\slave_relay_log_info.ibd. Cannot open
tablespace test_database/test_table which uses space ID: 3 at filepath:
.\test_database\test_table.ibd
You'll have to read the error closely. This says that test_database is preventing mysql from starting.
You could blow away the offending database, these steps fix the problem:
Make sure mysql and xampp is shut down completely.
Go to your directory where mysql is installed, mine is: C:\xampp\mysql\data
You should see a folder with the name of a database that you created. mine was test_database.
Create a new folder somewhere else called C:\xampp\mysql\data\mysql\backuptablespace
Drag and drop (don't delete) the offending database table folder to the backup directory.
Try to start mysql again. For me it started right up in 1 second as expected.
If it doesn't work, put the file back where you started and you'll be back where you started.
If you don't want to delete the database and don't have backups:
If you don't have backups of table data and mysql won't start because something is corrupted you'll have to use the process of elimination to guess-and-check your way to exactly what you did that corrupted it. Follow these steps:
Make a clone of the entire C:\xampp\ and store it somewhere safe so you can get back to where you started.
Use a "binary search" approach to try to locate the corrupted item in the mysql database. It could be a file, or a table, or a database, or a user or anything.
Delete the entire database and see if that allows mysql to start. If it does, then put back the database and try removing some of the tables. If it doesn't, then try yanking out something else until it does start.
Try removing these files from C:\xampp\mysql\data\mysql:
db.frm
db.MRD
db.MYI
db.opt
user.frm
user.MYD
user.MYI
When you get mysql to start, try putting things back until you find the one thing that you add which prevents it from starting. One bonus for this is you learn how mysql works under the hood.
Nuclear option:
Something you did screwed up the mysql server. An uninstall and reinstall of XAMPP should undo the corruption.
Add the following line below the [mysqld] section in the mysql config file (my.ini) and restart the apache web server and the mysql service afterwards.
[mysqld]
innodb_force_recovery = 4
My Xampp MySQL worked just follows as below:
01.Go to mysql/data/ directory
02. delete the ibdata1 & ib_logfile*(ib_logfile0,ib_logfile1,ib_logfile101) file
03. restart xampp server
Step 1 : Close Xampp controller completely
Step 2 : Open C:\xampp\mysql\backup
Step 3 : Copy all the files from backup folder
Step 4 : Open C:\xampp\mysql\data
Step 5 : Paste the all the files in data folder
Step 6 : Re-start the Xampp controller
Never delete this file (ibdata1) because all your data will be deleted!!!
I suggest three ways :
A:
1- Exit from XAMPP control panel.
1- Rename the folder mysql/data to mysql/data_old (you can use any name)
2- Create a new folder mysql/data
3- Copy the content that resides in mysql/backup to the new mysql/data folder
4- Copy all your database folders that are in mysql/data_old to mysql/data (skipping the mysql, performance_schema, and phpmyadmin folders from data_old)
5- Finally copy the ibdata1 file from mysql/data_old and replace it inside mysql/data folder
6- Reastart your system.
B:
1- Stop all sql services.
2- Next, start all sql services again.
C:
1- Open XAMPP control panel
2- Click on Config button, in front of mysql, click on my.ini
3- change client port and server port.
I have tried all the above answers but it didn't work for me. So finally I tried the below approach and it works 100% for me.
If you are worried about following the below steps you can take a backup of the entire XAMPP folder for the safe side.
Step 1: Rename the c:\xampp\mysql\data folder to c:\xampp\mysql\data_bkp
Step 2: Create a new folder c:\xampp\mysql\data.
Step 3: Copy the content, that is present inside c:\xampp\mysql\backup to the new c:\xampp\mysql\data folder.
Step 4: Copy all your database folders c:\xampp\mysql\data_bkp to c:\xampp\mysql\data (Note: Don't copy mysql, performance_schema, and phpmyadmin folders).
Step 5: Copy the ibdata1 file from c:\xampp\mysql\data_bkp and replace it inside the c:\xampp\mysql\data folder.
Step 6: Start MySQL from the XAMPP control panel.
I also faced this issue and this is how I solved.
1. Make sure xampp is not under sub-directory. For example, it should be C:\xampp
2. You might need to run as administrator in running the application.
Hope this will work!
in my case i did following steps and it worked:
In Xampp control panel click on "Services" button from the right side toolbar
Then find "MySQL" from the services List
Click on it and from the left side of the panel click on "stop"
Turn back in Xampp control panel and click on start.
move xampp/mysql/backup files into xampp/mysql/data
RUN XAMPP as Administrator(make sure mysql is installed you can see a green tick if is installed)
Hope it helps!
Simple solution
Open shell from Xampp Control Panel
mysqld --console --skip-grant-tables --skip-external-locking
Then again open an other shell and run
mysqlcheck -r --databases mysql --use-frm
Now close both shells and restart the xampp.
I have resolved the problem by ending the task for mysqlid on Task Manager.
Here is the way you can solve this problem:
Go to C:\xampp\mysql\data
You will see a folder named as mysql/data
Rename that folder from mysql/data to something else like mysql/data_not_useful any name that you want to give.
Create a new folder named as mysql/data.
Copy all the files of the mysql/backup and paste in mysql/data.
Now go to mysql/data_not_useful and copy the file ibdata1 from there.
Then paste it in mysql/data (You have to replace the file).
Restart your xampp server.
Now run your mysql server.
Here is what I did. I restarted my computer. Next I run services.msc. I stopped the MySQL service then restarted it. The restarted the Xampp server.
No solution above worked for me. then I did below:
I deleted all the files inside C:\xampp\mysql\data\ directory except folders in this directory.
It worked perfectly fine but my previous databases are not working now.
So do above if you don't care it will delete all your previous databases in phpmyadmin.
i was facing the same issue and none of the solutions stated above helped me.
i went to the mysql configuration file (my.ini) and changed the port number under [mysqld].By default mysql runs on 3306 port.
port= 3306
i changed it to ,
port= 8111
Then run as Administrator.Finally this worked for me.
This means that you already have a MySQL database running at port 3306.
In the XAMPP control panel, press the 'Config' button and after that press 'my.ini'. After this, Ctrl-F and search for '3306'. Replace any '3306' that you find with a different port number of your choice (you could choose 3307 or 3308 - I chose 2811 and it worked).
After you have replaced every location where '3306' is written, save the file and press 'Start' on the control panel again.
Had the same issue.
STAEP 1
backup folder xampp/mysql/data (saved it as `xampp/mysql/_old_data`).
STAEP 2
Go to xampp/mysql/data and deleted all the files but not folders! With databases.
STAEP 3
At this stage your database will not work. You need to go to your backup folder `xampp/mysql/_old_data` and copy over "`ibdata1`" file to `xampp/mysql/data`.
After that everything work as expected including phpmyadmin and console.
STAEP 4
If this does not help. You can remove xampp/mysql/data folder and rename xampp/mysql/_old_data back to xampp/mysql/data.
(ROLLBACK) and try different things.
Xampp stop Instantly after start.
copy all files and folder from C:\xampp\mysql\backup and paste into
C:\xampp\mysql\data.
Go to xampp/mysql/data
Rename folder from data to data_backup
Create new folder data
Copy files from backup to data
delete ibdata1 from data folder
Copy ibdata1 from data_backup folder to data folder
Copy your all database from data_backup to data folder
Restart xampp. It will start working
Copy all files from xampp/mysql/backup/ then paste into /xampp/mysql/data/
Restart mysql.
0.cntr+alt+delet
1.end task mysqld
2.Restart mysql.

How to solve "Error: MySQL shutdown unexpectedly"?

When I open XAMPP and click start MySQL button and it gives me an error.
I had started it just before, but now it isn't working.
12:19:12 PM [mysql] Attempting to start MySQL app...
12:19:12 PM [mysql] Status change detected: running
12:19:13 PM [mysql] Status change detected: stopped
12:19:13 PM [mysql] Error: MySQL shutdown unexpectedly.
12:19:13 PM [mysql] This may be due to a blocked port, missing dependencies,
12:19:13 PM [mysql] improper privileges, a crash, or a shutdown by another method
12:19:13 PM [mysql] Press the Logs button to view error logs and check
12:19:13 PM [mysql] the Windows Event Viewer for more clues
12:19:13 PM [mysql] If you need more help, copy and post this
12:19:13 PM [mysql] entire log window on the forums
Here is the contents of the error log:
2013-08-02 12:19:12 4536 [Note] Plugin 'FEDERATED' is disabled.
2013-08-02 12:19:12 f64 InnoDB: Warning: Using innodb_additional_mem_pool_size is DEPRECATED. This option may be removed in future releases, together with the option innodb_use_sys_malloc and with the InnoDB's internal memory allocator.
2013-08-02 12:19:12 4536 [Note] InnoDB: The InnoDB memory heap is disabled
2013-08-02 12:19:12 4536 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
2013-08-02 12:19:12 4536 [Note] InnoDB: Compressed tables use zlib 1.2.3
2013-08-02 12:19:12 4536 [Note] InnoDB: Not using CPU crc32 instructions
2013-08-02 12:19:12 4536 [Note] InnoDB: Initializing buffer pool, size = 16.0M
2013-08-02 12:19:12 4536 [Note] InnoDB: Completed initialization of buffer pool
2013-08-02 12:19:12 4536 [Note] InnoDB: Highest supported file format is Barracuda.
2013-08-02 12:19:12 4536 [Note] InnoDB: The log sequence numbers 0 and 0 in ibdata files do not match the log sequence number 1616798 in the ib_logfiles!
2013-08-02 12:19:12 4536 [Note] InnoDB: Database was not shutdown normally!
2013-08-02 12:19:12 4536 [Note] InnoDB: Starting crash recovery.
2013-08-02 12:19:12 4536 [Note] InnoDB: Reading tablespace information from the .ibd files...
The most important error message is here:
2013-08-02 12:19:12 4536 [ERROR] InnoDB:
Attempted to open a previously opened tablespace.
Previous tablespace mysql/innodb_table_stats uses space ID: 1 at filepath: .\mysql\innodb_table_stats.ibd.
Cannot open tablespace xat/payments which uses space ID: 1 at filepath: .\xat\payments.ibd
The rest of the log:
InnoDB: Error: could not open single-table tablespace file .\xat\payments.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.
What is the cause of these errors and how can I rectify them?
IMPORTANT: do NOT delete ibdata1 file. You could destroy all your databases.
Instead, first try using the MySQL backup folder which is included with XAMPP. So do next steps:
Rename folder mysql/data to mysql/data_old
Make a copy of mysql/backup folder and name it as mysql/data
Copy all your database folders from mysql/data_old into mysql/data (except mysql, performance_schema, and phpmyadmin folders)
Copy mysql/data_old/ibdata1 file into mysql/data folder
Start MySQL from XAMPP control panel
And, voilà!
EDIT (January 7th 2023)
As mentioned by some users, this is an emergency solution, not a permanent one. After recovering your data is strongly recommended to back it up, and reinstalling XAMPP, because the failure is related to a malfunction from some of the files of XAMPP, not the databases.
IMPORTANT Deleting this file may render any existing MySQL data unusable. Use with caution
Hey I just did this and it worked:
exit Xampp server
go to your C:\xampp\mysql\data directory
delete the ibdata1 file
restart xampp server
It should work
Jun 2022
Disclaimer
Although many people said 'it worked' and very few say 'it didn't'.
It is hard to say what could be the cause and it is not working. Personally, the solution provided below worked for me and I didn't get any issues so far hence I am sharing this.
I don't suggest uninstalling, so you can basically back up the file and try this solution. If it doesn't work then place those files again.
Worked on other Versions
This issue works on other xampp versions too.
I have not tested personally, but some users have.
( If you have tested on a different version, let me know in the comment, I will add it here)
XAMPP v8.1.6 - Saeid Z
XAMPP v7.4.16 - CapelliC
XAMPP v3.3.0 - Myself
Feb 2022 (Problem)
I had the same problem today (2 feb 2022).
I fixed this using the same solution I mentioned below (See Dec 2021 (Solution))
XAMPP Issue Screenshot
XAMPP Fixed
Dec 2021 (Solution)
Since this question is active continuously,
I will try my best to solve it.
My issue
I visit this post every time this issue happens. The only thing I tried was that I uninstalled xampp and reinstalled it, which fixed the problem. That was on my old system.
I am using windows 10 brand new with no unwanted software or issues, and I got this unexpected shutdown again after a long time. I came to this question, hoping someone would tell me actually what was going on instead of fixing these issues. But unfortunately, I could not find it.
Just to clarify, my new issue is not with
port
unexpected shutdown
windows stuck
unwanted software
virus or malware.
One day I turned on xampp, and it stops working.
Method 1 (22 Dec 2021)
Stop MySQL.
Go to the C:/xampp/mysql directory and copy the data folder and keep it somewhere else (probably in another drive) as a backup.
Go to your original data folder (C:/xampp/mysql) and sort the files by 'Type.'
Select the files that have the type INFO File and delete them (screenshot below).
Start MySQL. It should work now.
Method 1 Screenshot
Important
Not necessarily the solution above will always fix the issue. Sometimes it will not. To avoid the major risk of losing the data, try these.
Turn on MySQL in the Control Panel ONLY IF NEEDED.
DO NOT set the XAMPP Control Panel to turn it on windows startup.
Back up DB whenever possible. If not try to back up every weekend.
PS: I will try to update this answer whenever the above method(s) don't work. I will try to explain it in the simplest way possible without uninstalling XAMPP.
Let me know if it works for you.
If the answers mentioned above are not working, you can try deleting all the files in data, except for the folder
Goto:
C:\xampp\mysql\data
After that:
Goto: C:\xampp\mysql\bin
then open with notepad my.ini
, Its look like this.
Then delete or put into comment the port 3306 and change it to 8111 then run xamp with administrator and its work well.
Go to mysql/data/
Delete all random files (except the actual database folders)
Restart Apache and MySQL.
It should fix it.
WORKING SOLUTION :- Follow the below listed steps.
Step 1. Rename the folder c:\xampp\mysql\data to c:\xampp\mysql\data_bkp (you can use any name).
Step 2. Create a new folder c:\xampp\mysql\data.
Step 3. Copy the content that resides in mysql\backup to the new mysql\data folder.
Step 4. Copy all your database folders that are in mysql\data_bkp to mysql\data (skipping the mysql, performance_schema, and phpmyadmin folders from mysql\data_bkp).
IMPORTATN NOTE :- Please do not replace the existing files while pasting(click skip these files)
Step 5. Finally copy the ibdata1 file from mysql\data_bkp and replace it inside mysql\data folder.
Step 6. Start MySQL from XAMPP control panel.
And, Its DONE . No databases lost, no ports changed, no run as administrator, no force recovery, no kill mysqld process, no restoring from previous versions, no more errors.
Just follow two steps
go to xampp\mysql\backup
copy everything from backup folder
go to xampp\mysql\data
paste everything in data folder copied from backup folder
Thats all.
Also follow the video description to fix without losing any data:
https://www.youtube.com/watch?v=hB1wshpP3Jc
Or follow the article description to fix without losing any data:
https://webjourney.dev/error-mysql-shutdown-unexpectedly-solve-without-loosing-any-data-webjourney
UPDATE APRIL (2022)
Rename folder mysql/data to mysql/data_old
Make a copy of mysql/backup folder and name it as mysql/data
Copy all your database folders and mysql folder from mysql/data_old into mysql/data
Copy mysql/data_old/ibdata1 file into mysql/data folder
Start MySQL from XAMPP control panel
REFERENCE
https://www.youtube.com/watch?v=ipMedkjMupw&ab_channel=GeekyScript
When you're not running XAMPP as an administrator, shutting down MySQL frequently causes corruption which means you have to repair or delete your tables. To avoid this you need to either run XAMPP as an administrator, or use the proper command prompt method for shutting down MySQL.
You can delete ibdata1 as Kratos suggests, but this can leave you with a broken database as other pieces of your database are still in the /mysql/data/ folder. In my case, this residual data stopped me successfully installing WordPress.
A cleaner way of undoing the damage is to revert your whole /mysql/data/ folder. Windows has built-in folder versioning — right click on /mysql/data/ and select Restore previous versions. You can then delete the current contents of the folder and replace it with the older version's contents.
Addendum: To ensure that you don't forget to run XAMPP as an administrator you can right click the XAMPP shortcut, go to Properties, then Advanced, and finally tick Run as administrator.
I got the same kind of error in my C:\xampp\mysql\data\mysql_error.log when trying to start mysql.
2013-08-05 01:20:32 6780 [ERROR] InnoDB: Attempted to open a previously
opened tablespace. Previous tablespace mysql/slave_relay_log_info uses
space ID: 3 at filepath: .\mysql\slave_relay_log_info.ibd. Cannot open
tablespace test_database/test_table which uses space ID: 3 at filepath:
.\test_database\test_table.ibd
You'll have to read the error closely. This says that test_database is preventing mysql from starting.
You could blow away the offending database, these steps fix the problem:
Make sure mysql and xampp is shut down completely.
Go to your directory where mysql is installed, mine is: C:\xampp\mysql\data
You should see a folder with the name of a database that you created. mine was test_database.
Create a new folder somewhere else called C:\xampp\mysql\data\mysql\backuptablespace
Drag and drop (don't delete) the offending database table folder to the backup directory.
Try to start mysql again. For me it started right up in 1 second as expected.
If it doesn't work, put the file back where you started and you'll be back where you started.
If you don't want to delete the database and don't have backups:
If you don't have backups of table data and mysql won't start because something is corrupted you'll have to use the process of elimination to guess-and-check your way to exactly what you did that corrupted it. Follow these steps:
Make a clone of the entire C:\xampp\ and store it somewhere safe so you can get back to where you started.
Use a "binary search" approach to try to locate the corrupted item in the mysql database. It could be a file, or a table, or a database, or a user or anything.
Delete the entire database and see if that allows mysql to start. If it does, then put back the database and try removing some of the tables. If it doesn't, then try yanking out something else until it does start.
Try removing these files from C:\xampp\mysql\data\mysql:
db.frm
db.MRD
db.MYI
db.opt
user.frm
user.MYD
user.MYI
When you get mysql to start, try putting things back until you find the one thing that you add which prevents it from starting. One bonus for this is you learn how mysql works under the hood.
Nuclear option:
Something you did screwed up the mysql server. An uninstall and reinstall of XAMPP should undo the corruption.
Add the following line below the [mysqld] section in the mysql config file (my.ini) and restart the apache web server and the mysql service afterwards.
[mysqld]
innodb_force_recovery = 4
My Xampp MySQL worked just follows as below:
01.Go to mysql/data/ directory
02. delete the ibdata1 & ib_logfile*(ib_logfile0,ib_logfile1,ib_logfile101) file
03. restart xampp server
Step 1 : Close Xampp controller completely
Step 2 : Open C:\xampp\mysql\backup
Step 3 : Copy all the files from backup folder
Step 4 : Open C:\xampp\mysql\data
Step 5 : Paste the all the files in data folder
Step 6 : Re-start the Xampp controller
Never delete this file (ibdata1) because all your data will be deleted!!!
I suggest three ways :
A:
1- Exit from XAMPP control panel.
1- Rename the folder mysql/data to mysql/data_old (you can use any name)
2- Create a new folder mysql/data
3- Copy the content that resides in mysql/backup to the new mysql/data folder
4- Copy all your database folders that are in mysql/data_old to mysql/data (skipping the mysql, performance_schema, and phpmyadmin folders from data_old)
5- Finally copy the ibdata1 file from mysql/data_old and replace it inside mysql/data folder
6- Reastart your system.
B:
1- Stop all sql services.
2- Next, start all sql services again.
C:
1- Open XAMPP control panel
2- Click on Config button, in front of mysql, click on my.ini
3- change client port and server port.
I have tried all the above answers but it didn't work for me. So finally I tried the below approach and it works 100% for me.
If you are worried about following the below steps you can take a backup of the entire XAMPP folder for the safe side.
Step 1: Rename the c:\xampp\mysql\data folder to c:\xampp\mysql\data_bkp
Step 2: Create a new folder c:\xampp\mysql\data.
Step 3: Copy the content, that is present inside c:\xampp\mysql\backup to the new c:\xampp\mysql\data folder.
Step 4: Copy all your database folders c:\xampp\mysql\data_bkp to c:\xampp\mysql\data (Note: Don't copy mysql, performance_schema, and phpmyadmin folders).
Step 5: Copy the ibdata1 file from c:\xampp\mysql\data_bkp and replace it inside the c:\xampp\mysql\data folder.
Step 6: Start MySQL from the XAMPP control panel.
I also faced this issue and this is how I solved.
1. Make sure xampp is not under sub-directory. For example, it should be C:\xampp
2. You might need to run as administrator in running the application.
Hope this will work!
Simple solution
Open shell from Xampp Control Panel
mysqld --console --skip-grant-tables --skip-external-locking
Then again open an other shell and run
mysqlcheck -r --databases mysql --use-frm
Now close both shells and restart the xampp.
in my case i did following steps and it worked:
In Xampp control panel click on "Services" button from the right side toolbar
Then find "MySQL" from the services List
Click on it and from the left side of the panel click on "stop"
Turn back in Xampp control panel and click on start.
move xampp/mysql/backup files into xampp/mysql/data
RUN XAMPP as Administrator(make sure mysql is installed you can see a green tick if is installed)
Hope it helps!
I have resolved the problem by ending the task for mysqlid on Task Manager.
Here is the way you can solve this problem:
Go to C:\xampp\mysql\data
You will see a folder named as mysql/data
Rename that folder from mysql/data to something else like mysql/data_not_useful any name that you want to give.
Create a new folder named as mysql/data.
Copy all the files of the mysql/backup and paste in mysql/data.
Now go to mysql/data_not_useful and copy the file ibdata1 from there.
Then paste it in mysql/data (You have to replace the file).
Restart your xampp server.
Now run your mysql server.
Here is what I did. I restarted my computer. Next I run services.msc. I stopped the MySQL service then restarted it. The restarted the Xampp server.
No solution above worked for me. then I did below:
I deleted all the files inside C:\xampp\mysql\data\ directory except folders in this directory.
It worked perfectly fine but my previous databases are not working now.
So do above if you don't care it will delete all your previous databases in phpmyadmin.
i was facing the same issue and none of the solutions stated above helped me.
i went to the mysql configuration file (my.ini) and changed the port number under [mysqld].By default mysql runs on 3306 port.
port= 3306
i changed it to ,
port= 8111
Then run as Administrator.Finally this worked for me.
This means that you already have a MySQL database running at port 3306.
In the XAMPP control panel, press the 'Config' button and after that press 'my.ini'. After this, Ctrl-F and search for '3306'. Replace any '3306' that you find with a different port number of your choice (you could choose 3307 or 3308 - I chose 2811 and it worked).
After you have replaced every location where '3306' is written, save the file and press 'Start' on the control panel again.
Had the same issue.
STAEP 1
backup folder xampp/mysql/data (saved it as `xampp/mysql/_old_data`).
STAEP 2
Go to xampp/mysql/data and deleted all the files but not folders! With databases.
STAEP 3
At this stage your database will not work. You need to go to your backup folder `xampp/mysql/_old_data` and copy over "`ibdata1`" file to `xampp/mysql/data`.
After that everything work as expected including phpmyadmin and console.
STAEP 4
If this does not help. You can remove xampp/mysql/data folder and rename xampp/mysql/_old_data back to xampp/mysql/data.
(ROLLBACK) and try different things.
Xampp stop Instantly after start.
copy all files and folder from C:\xampp\mysql\backup and paste into
C:\xampp\mysql\data.
Go to xampp/mysql/data
Rename folder from data to data_backup
Create new folder data
Copy files from backup to data
delete ibdata1 from data folder
Copy ibdata1 from data_backup folder to data folder
Copy your all database from data_backup to data folder
Restart xampp. It will start working
Copy all files from xampp/mysql/backup/ then paste into /xampp/mysql/data/
Restart mysql.
0.cntr+alt+delet
1.end task mysqld
2.Restart mysql.

MySQL InnoDB database restore

I have to restore a database that has been inadvertently DROPped in MySQL 5.0. From checking the backup files, I only seem to have .FRM files to hold the database data.
Can anyone advise whether this is all I need to perform a database restore/import from the backup, or are there other files I should have to hand to complete this?
.frm files are not the data files, they just store the "data dictionary information" (see MySQL manual). InnoDB stores its data in ib_logfile* files. That's what you need in order to do a backup/restore. For more details see here.
Restoring innodb:
(assuming your data folder is C:\ProgramData\MySQL\MySQL Server 5.5\data)
Copy the folders of the databases (named after the database name) you want to restore to C:\ProgramData\MySQL\MySQL Server 5.5\data
Copy the 3 ibdata files to the data folder ex. (C:\ProgramData\MySQL\MySQL Server 5.5\data)
_ib_logfile0
_ib_logfile1
_ibdata1
Get the size of the _ib_logfile0 in MB (it should be the same as _ib_logfile1) by File Right click -> Properties
Edit the mysql config file (mysql\bin\my.ini) for the innodb_log_file_size=343M to be exactly the ibdata files size
Run
mysqld --defaults-file=mysql\bin\my.ini --standalone --console
--innodb_force_recovery=6
Now your data should be back in your database. Export them using phpmysql or any other tool
The detailed solution you can found here:
http://www.unilogica.com/mysql-innodb-recovery/ (Article in Portuguese)
Besides the flag of innodb_force_recovery, I found another solution: innodb_file_per_table, that splits InnoDB tables in each file like MyISAM tables.
In a crash recovery you can lost less data than in single file ibdata1.