331

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?

Dharman
  • 26,923
  • 21
  • 73
  • 125
Austin
  • 3,323
  • 3
  • 11
  • 11

66 Answers66

1288

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:

  1. Rename folder mysql/data to mysql/data_old
  2. Make a copy of mysql/backup folder and name it as mysql/data
  3. Copy all your database folders from mysql/data_old into mysql/data (except mysql, performance_schema, and phpmyadmin folders)
  4. Copy mysql/data_old/ibdata1 file into mysql/data folder
  5. Start MySQL from XAMPP control panel

And, voilà!

Fabrizio Valencia
  • 13,339
  • 3
  • 13
  • 19
  • 79
    This is the best answer, doesn't ask you to delete any files or folder and importantly, it works. – gegobyte Jun 30 '20 at 06:46
  • 2
    I also had to copy back the files ib_logfile0 and ib_logfile1 to prevent this kind of errors showing up in the log: [ERROR] InnoDB: Page [page id: space=1, page number=3] log sequence number 10638137774 is in the future! Current system log sequence number 1792801. [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to https://mariadb.com/kb/en/library/innodb-recovery-modes/ for information about forcing recovery. This https://stackoverflow.com/a/20617180/867327 refers to innodb_force_recovery – patrox Jul 09 '20 at 07:42
  • 3
    This is the best answer – iranimij Aug 08 '20 at 03:20
  • 33
    I've resorted to this answer sooo many times that I even wrote a PowerShell script to automate the process: https://gist.github.com/josemmo/24e35f2b4984a4370ce2c164f5956437 – josemmo Aug 28 '20 at 18:50
  • 13
    legend !! you saved my life – Hiệp Nguyễn Sep 07 '20 at 17:33
  • 8
    Yes, this is best answer. my bad I have not tried it first. Excellent answer. You saved my db data and lots of hassles. Hats off to you man! – Nilesh Sep 10 '20 at 16:20
  • 4
    As per @josemmo gist, it's important to note to exclude mysql, performance_schema, phpmyadmin when copying directories to mysql/data – claw68 Sep 13 '20 at 05:08
  • 2
    It did work, but I deleted `ibdata1` file based on incorrect advice above. Now I lost all of my tables. I've got only table names with no content inside. Is there any way to recover the `ibdata1` that I deleted? – Brian Sep 13 '20 at 17:46
  • 1
    I installed the newest version of XAMPP. It was working fine for a while. Now again MySQL stopped working and I am getting the same error message. Is there something wrong with XAMPP? Why recently I've got this problem with XAMPP? – Brian Sep 20 '20 at 21:10
  • 1
    Somebody should try just deleting the buffer and log files. I have a nudge that might be an even faster fix. – ViBoNaCci Oct 09 '20 at 17:05
  • 1
    This should definitely be the top answer, the other is just plain dangerous to databases! – BShimm Oct 12 '20 at 19:05
  • 1
    Top Correct answer – Simba Oct 15 '20 at 05:19
  • 2
    Seriously, give this man the right answer mark. The "correct" answer might do it, but it's literally a coinflip. You might keep your data, you might get screwed over so hard you'll want to throw your computer out of your window. This solution didn't make anyone take a 50/50 chance of losing his database data. – I try so hard but I cry harder Oct 24 '20 at 22:41
  • 1
    Great, this must be the correct answer for sure. Not a single data loss. Great work (Y) – Muhammad Shareyar Oct 27 '20 at 05:36
  • 1
    Saved my a whole lot of hassle, thank you so much for this! – lloydcox Nov 30 '20 at 11:01
  • 1
    It works. The problem has been solved. Thank you sir for your effort. – Ashiful Islam Prince Dec 10 '20 at 08:55
  • This method works but My DB was deleted completely – Mohamed Raza Dec 15 '20 at 05:03
  • This should be the correct answer. Thanks! Saved my day! – Javier Vargas Dec 21 '20 at 17:31
  • Sadly I've been experiencing this problem way to constantly -each 15 days or so- even though I'm openning Xampp as admin and closing it before shutdown. I'll try also shutting it down whenever I sleep pc to see if it is related to that. – Fer Toasted Dec 24 '20 at 18:35
  • worked on the first attempt - thank you. – Jerry King Dec 26 '20 at 05:07
  • This is the best answer! Thank you so much! – Thanh Nguyen Jan 09 '21 at 06:53
  • This should be the accepted answer! Thanks! – Renan Coelho Jan 10 '21 at 09:16
  • Everyone says this works and it really does work, thanks alot! – how2code Jan 13 '21 at 00:53
  • Exactly the best answer! – Morani Jan 15 '21 at 13:23
  • 1
    It worked , but it happens too often . Does anyone why this is happening so often ? – Prince Arora Jan 29 '21 at 06:01
  • This is magic, thank god you existed in this world. – Jovylle Bermudez Mar 01 '21 at 09:31
  • Can someone explain, why this thing happen? – Satish Mar 07 '21 at 14:19
  • Best answer ever. My mysql at xampp 7.1 just stopped to work, no reason no error in log. This happened second time (on wordpress database) . First time i ended up importing all databases + reinstall, now tried this, and worked fabulously, saved my day man :) – Jiro Matchonson Mar 16 '21 at 16:24
  • Machine crashed, Database seems to be stucked. Every time I want to start the MySQL via XAMPP it shuts down instantly again. This trick fixed m issues without any data loss, That's a +1 from me ! – Matthew Developer Mar 28 '21 at 18:49
  • You saved my database. I have had this same issue about 3-4 times before, this answer is the best ever. It worked seemlessly. – Joseph Ajibodu Mar 29 '21 at 08:43
  • Worked charmingly in Mar 2021. Thank You for saving my life... – bbidadi Mar 30 '21 at 07:43
  • MySQL service started but accessing phpmyadmin results in " MySQL said: Documentation Cannot connect: invalid settings. mysqli::real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server." Any ideas how to solve this? Thanks! – Dimentica Mar 30 '21 at 13:04
  • This saved me twice already. But why does it happen? It happened to me again today and google led me here again. – palekjram Apr 07 '21 at 04:16
  • In Addition to the answer: copy all folders from mysql/data_old to mysql/data to get all the database back. – Freelancer Mahmud Apr 15 '21 at 06:10
  • I celebrate this answer too! – Fabian Andiel Apr 29 '21 at 06:43
  • I have had xampp mysql stop working seemingly randomly a few times. It's most often after I restart for whatever reason, but I feel like each time is after a Windows Update. Regardless, this saved my rear once. It has not worked each time, but the one time it worked is enough for me to say THANK YOU! – Gurnzbot May 07 '21 at 02:06
  • Perfect answer. It worked like charm. Thanks – Dip May 10 '21 at 12:22
  • Looks like it Worked for so many people but unfortunately it didn't work for me. And i was randomly into those folders so what i did was (I also make a copy of data folder it's important because after installation all those data folder will be complete fresh) I went inside `xampp/mysql/bin` folder there i nagivate to `mysql_install_db` and it works fine. – Sandesh Poudel May 27 '21 at 04:29
  • Worked like a charm! Thank you. – Luke Galea Jul 05 '21 at 07:01
  • I worked, but you have also to skip the folder "test" in Step 4. – joan16v Jul 20 '21 at 05:38
  • Thanks for an amazing solution. :) Worked like a charm. You deserve more than just upvotes. :D – Utpal - Ur Best Pal Jul 25 '21 at 10:16
  • ohh bro, you are life saver for me and many others. – bhavinjr Jul 26 '21 at 15:56
  • I have just uploaded over 1000 data to my tables over the past month. I thought that I'd lost it ... :( I thank you from the bottom of my heart! – charco Jul 27 '21 at 09:23
  • You just saved tons of my projects database. Thank you man. – Jyotirmoy Aug 01 '21 at 09:42
  • Thanks!! it helped a lot. Saved a whole lot of time... ^_^ – Himanshu Bansal Aug 13 '21 at 09:17
  • I have lost my data using this method. – Shiva Aug 23 '21 at 06:58
  • Awesome !! man. solved a latency problem , happy now – Atik Hashmee Aug 29 '21 at 18:35
  • Thanks, I have renamed the folder created new folder data copy the backup file into it, and its works. – LogGurkha Sep 15 '21 at 06:15
  • Thank you so much. Its work like magic. – developerExecutive Sep 17 '21 at 12:58
  • genious great work – Hamza Qureshi Sep 21 '21 at 11:05
  • You are Life saver – aslamdoctor Oct 12 '21 at 01:04
  • Thank you very much – Ali Abbasov Nov 11 '21 at 13:06
  • Thank you! most of time I deleted that file when I have this problem. but this way is working perfectly and its the best way. – Tharuka Dananjaya Dec 05 '21 at 03:46
  • This worked for me . Thank you so much . Don't know what caused the glitch in my xampp setup. – Vikrant Dec 09 '21 at 09:36
  • All these solutions delete your existing User Data. – Paul Trimor Dec 15 '21 at 16:42
  • works for me... – Umar Adil Dec 20 '21 at 06:38
  • It worked, thanks – Loganathan Natarajan Dec 29 '21 at 17:08
  • I had done the same steps but still the same problem and after that, i change the port from 3306 to 3308 and its start working thanks a lot – Deepak Goyal Jan 20 '22 at 04:51
  • Work like a charm. thank you – Rohit vm Jan 20 '22 at 05:47
  • it worked but I couldn't connect to the DB until I changed the DB User in all my websites to "root" and Password to "". What could be the reason? – Gordons Jan 22 '22 at 22:12
  • WOW~~~. Thank you. – Silverstar Jan 27 '22 at 16:15
  • Love you , great solution – devpro Feb 10 '22 at 13:29
  • I've been using xampp for the last 4 years and every time i get this error I feel like I'm done with coding. landed the first time on this question and your answer worked perfectly on the first attempt only Thanks. – Kunal Rajput Feb 14 '22 at 06:32
  • This saved my day Thanks @Fabrizio Valencia – Sreejith vs Feb 21 '22 at 15:29
  • You are my God! – Erfan Paslar Mar 07 '22 at 08:04
  • This worked, but only after I copied ALL the files in "mysql/" (but I still excluded `mysql/mysql/`, `mysql/performance_schema/`, and `mysql/phpmyadmin/` folders. Failing to copy *all* the files, and not just `ibdata1`, resulted in phpmyadmin complaining that "mydatabase.mytable doth not exist" for every one of my tables in all my databases. I don't know which file inspecific I missed (I made sure to copy `ibdata1` but that wasn't sufficient on its own), so maybe this answer could be updated to clarify which ones I should've copied? I'm ignorant here. – Jamin Grey Apr 06 '22 at 19:07
  • Sweet! Its working like a charm – Mahder Apr 18 '22 at 10:55
  • 1
    No use, still keep repeating the same issue after few days. – Thirsty Six Apr 29 '22 at 05:39
  • Still facing the problem. Can you please mention any other possible problem ?? – Muhammad Afzaal May 08 '22 at 07:11
  • The best solution without any risk – Roshan Zaid May 21 '22 at 05:44
  • It's not working for me. This is the actual issue "mysqld.exe: Table '.\mysql\db' is marked as crashed and should be repaired" - I solved it used this method https://stackoverflow.com/a/60576807/1662058 – Thirsty Six Jun 01 '22 at 05:18
195

IMPORTANT Deleting this file may render any existing MySQL data unusable. Use with caution

Hey I just did this and it worked:

  1. exit Xampp server
  2. go to your C:\xampp\mysql\data directory
  3. delete the ibdata1 file
  4. restart xampp server

It should work

Machavity
  • 29,816
  • 26
  • 86
  • 96
Kratos
  • 2,359
  • 1
  • 10
  • 2
  • 35
    This works and should likely be marked as the correct answer. However *rename* the file to ibdata1.bak rather than delete it. Just to be save. – Lorenz Lo Sauer Sep 03 '13 at 12:13
  • 23
    This will, of course, destroy all the data which was stored in that file (all the InnoDB tables which were created before setting `innodb_file_per_table` to enabled). The methods suggested in the log message seem suprtior to me. – Tgr Oct 12 '13 at 10:50
  • I added `innodb_force_recovery = 1` within `[mysqld]` section, in my mysql configuration file, restarted mysql, and then removed the line, this worked! – Anil Feb 03 '14 at 09:32
  • 17
    I also had to delete `ib_logfile0` and `ib_logfile1` to get it to work – Allan Macmillan Jun 19 '14 at 18:58
  • 1
    I had to delete all of these files: `mysql_error.log` `aria_log.00000001` `aria_log_control` `ib_logfile0` `ibdata1` – Robin Hossain Oct 23 '16 at 12:02
  • 14
    Ouch! Blowing away `ibdata1` is equivalent to losing all your data (or at least all that are `ENGINE=Innodb` ! – Rick James Mar 14 '17 at 04:16
  • 21
    The most upvoted unexplained reckless thing you can do – user10089632 Jan 14 '18 at 10:36
  • 1
    Deleting mysql_error.log aria_log.00000001 aria_log_control ib_logfile0 ibdata1 did not work. I deleted all files except folders in C:\xampp\mysql\data to let it work again :) ! – Trees May 10 '20 at 13:39
  • 3
    It should not be this way. Ok there are some corrupted files, but you should use the `backup` folder to restore everything, such as the XAMPP control message panel suggest. This could be a better way of doing it: https://stackoverflow.com/a/61859561/5373542 – Fabrizio Valencia May 17 '20 at 22:27
  • 2
    Fabrizio Valencia's answer (https://stackoverflow.com/questions/18022809/xampp-mysql-shutdown-unexpectedly/61859561#61859561) is the only one that worked for me (and it was non-destructive). Highly recommend. – HartleySan May 26 '20 at 11:42
  • 2
    This might "work" in that you can restart MySQL, but it will no doubt result in more headaches as your db will be gone. See the answer that begins with "Stop there! Please do not delete anything!" – sacredfaith Aug 10 '20 at 08:59
  • This broke my database. See the answer from Fabrizio Valencia. – Javier Vargas Dec 21 '20 at 17:37
  • this worked just fine, xampp refused to run SQL after fresh installing, so there is no database to worry about, nothing other than this worked. – Amr May 18 '21 at 15:32
  • Still works in 2021. I must give you credit for this. Spent almost half a day looking for solution (using the wrong search terms). Thanks for this. – Oluwaseyitan Baderinwa Jul 02 '21 at 13:56
  • I tried this, it's working.. after some time it's showing the same issue.. even i changed the mysql port.. No Luck. – Thirsty Six Feb 28 '22 at 05:30
63

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

enter image description here

After that: Goto: C:\xampp\mysql\bin

then open with notepad my.ini , Its look like this.

enter image description here

Then delete or put into comment the port 3306 and change it to 8111 then run xamp with administrator and its work well.

CloudBalancing
  • 989
  • 1
  • 7
  • 19
Mathew Magante
  • 1,031
  • 3
  • 14
  • 28
51
  1. Go to mysql/data/
  2. Delete all random files (except the actual database folders)
  3. Restart Apache and MySQL.

It should fix it.

Kerim
  • 1,101
  • 12
  • 12
47

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

enter image description here

XAMPP Fixed

enter image description here

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)

  1. Stop MySQL.
  2. Go to the C:/xampp/mysql directory and copy the data folder and keep it somewhere else (probably in another drive) as a backup.
  3. Go to your original data folder (C:/xampp/mysql) and sort the files by 'Type.'
  4. Select the files that have the type INFO File and delete them (screenshot below).
  5. Start MySQL. It should work now.

Method 1 Screenshot

enter image description here

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.

Dexter
  • 5,748
  • 3
  • 34
  • 32
31

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) enter image description here

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.

Rohit Saini
  • 449
  • 5
  • 11
  • 1
    Although this step works but makes sure you test it out. If you have an existing database table, **it will all break**. If you have a new installation of XAMPP then this might help you. – Dexter Sep 08 '21 at 01:55
  • @Dexter I have tested it on my machine having 10+ database tables. Nothing breaks for me. By the ways thanks for letting me know about this. – Rohit Saini Sep 08 '21 at 03:07
  • 1
    This work for me thank you – kantsverma Nov 01 '21 at 05:56
28

Just follow two steps

  1. go to xampp\mysql\backup copy everything from backup folder

  2. go to xampp\mysql\data paste everything in data folder copied from backup folder

  3. Thats all.

Also follow the video description to fix without losing any data:

https://www.youtube.com/watch?v=hB1wshpP3Jc

Nazmul Hoque
  • 507
  • 4
  • 8
  • This answer will fix the above error but will also cause another errror, your django migration table in your database will disappear, thus you'll get the error `django_migration table does not exist` – C-Bizz Oct 20 '21 at 03:32
  • This is because you have delete ibdata1 form your data directory. I have also mentioned follow the description link for solve without losing any data. – Nazmul Hoque Oct 20 '21 at 05:30
  • works like a charm, thanks! – 4 R4C81D Nov 29 '21 at 09:48
22

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.

Ryan Williams
  • 667
  • 5
  • 11
15

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
matinict
  • 2,322
  • 2
  • 25
  • 35
14

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:

  1. Make sure mysql and xampp is shut down completely.
  2. Go to your directory where mysql is installed, mine is: C:\xampp\mysql\data
  3. You should see a folder with the name of a database that you created. mine was test_database.
  4. Create a new folder somewhere else called C:\xampp\mysql\data\mysql\backuptablespace
  5. Drag and drop (don't delete) the offending database table folder to the backup directory.
  6. 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:

  1. Make a clone of the entire C:\xampp\ and store it somewhere safe so you can get back to where you started.
  2. 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.
  3. 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.
  4. Try removing these files from C:\xampp\mysql\data\mysql: db.frm db.MRD db.MYI db.opt user.frm user.MYD user.MYI

  5. 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.

Eric Leschinski
  • 135,913
  • 89
  • 401
  • 325
13

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
Harmlezz
  • 7,744
  • 25
  • 34
aog
  • 440
  • 3
  • 14
  • 7
    Read about what you are doing, before you do it: http://dev.mysql.com/doc/refman/5.0/en/forcing-innodb-recovery.html – marcovtwout Sep 30 '14 at 11:56
  • Thank you so much, really helped me a lot. – Lohn Claidon Oct 28 '14 at 05:10
  • 6
    it's better to start with value 1 and increment it each time it didn't work. Values 1-3 are considered save. 4-6 can corrupt data! – CoR Aug 18 '15 at 20:26
  • This helped me. As pointed out, use values 1-3 first. 2 worked on me. I had to dump all my database, reset mysql data using the back up folder then import the dumps. This is helpful if you want to keep your data – claw68 Sep 13 '20 at 05:42
12

UPDATE APRIL (2022)

  1. Rename folder mysql/data to mysql/data_old
  2. Make a copy of mysql/backup folder and name it as mysql/data
  3. Copy all your database folders and mysql folder from mysql/data_old into mysql/data
  4. 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

9

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.

enter image description here

C:
1- Open XAMPP control panel
2- Click on Config button, in front of mysql, click on my.ini

enter image description here

3- change client port and server port.

enter image description here

9

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

Cristik
  • 28,596
  • 24
  • 84
  • 120
Swap
  • 115
  • 1
  • 9
8

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!

SITHU
  • 143
  • 6
7

in my case i did following steps and it worked:

  1. In Xampp control panel click on "Services" button from the right side toolbar

  2. Then find "MySQL" from the services List

  3. Click on it and from the left side of the panel click on "stop"

  4. Turn back in Xampp control panel and click on start.

tomerpacific
  • 3,871
  • 11
  • 28
  • 48
Sobhan
  • 796
  • 1
  • 10
  • 22
5
  1. move xampp/mysql/backup files into xampp/mysql/data
  2. RUN XAMPP as Administrator(make sure mysql is installed you can see a green tick if is installed) List item

Hope it helps!

Jayant Rajwani
  • 627
  • 9
  • 16
5

Here is the way you can solve this problem:

  1. Go to C:\xampp\mysql\data
  2. You will see a folder named as mysql/data
  3. Rename that folder from mysql/data to something else like mysql/data_not_useful any name that you want to give.
  4. Create a new folder named as mysql/data.
  5. Copy all the files of the mysql/backup and paste in mysql/data.
  6. Now go to mysql/data_not_useful and copy the file ibdata1 from there.
  7. Then paste it in mysql/data (You have to replace the file).
  8. Restart your xampp server.
  9. Now run your mysql server.
Tomerikoo
  • 15,737
  • 15
  • 35
  • 52
Akash Kumar
  • 167
  • 3
  • 7
5

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.

4

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.

kyzen
  • 253
  • 1
  • 2
  • 15
4

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.

Aammad Ullah
  • 246
  • 3
  • 11
4

I have resolved the problem by ending the task for mysqlid on Task Manager.enter image description here

  • Thanks, it helped me. That soultion with deleting ib1 created for me new problems to solve. – Skotee Feb 17 '20 at 00:21
3

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.

Sksaif Uddin
  • 532
  • 14
  • 20
3

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.

3

I solved similar MySQL error & I think this answer will help you to fix the same type of MySQL database error. MySQL Error on XAMPP Control panel

Solution:

  • Go to the “data” directory in the mysql database.
  • I installed XAMPP on D: drive on my computer & the mysql “data” directory location of my computer was “D:\xampp\mysql\data\”. You may have different location.

Take Backup of MySQL “data” Folder

  • First of all you should create a backup of the “data” folder using any compression software.

  • Give a name like “data_backup.zip” or any type of compression you wish.

  • I used winrar compression software to compress & backup mysql “data” folder.

Rename the “data” folder

  • Rename the “data” folder to “data-oldfiles”. This is very important to rename the data directory to any new directory name.

Create a new “data” folder

  • Create a new folder and give the folder name as “data“
  • To solve the problem we need to create a new “data” directory in the mysql database.

Copy content from “backup” folder

  • Go to the “backup” folder and copy all files.
  • Paste the files from backup folder to data folder
  • Now start the MySQL database from XAMPP.
  • Your MySQL database will start properly without showing any error.

Transfer all MySQL projects Database, Data file & Log files

  • If you have many database which was used for various projects, then you have to transfer all database from “data-oldfiles” folder to “data” folder.

  • Copy all databases from the data-old files and paste to the data folder.

  • Now you have to copy the data file “ibdata1” & all log files “ib_logfile0, ib_logfile1 ” from data-old files folder to the data folder.

  • If you have many id_logiles then copied all of them.

  • Now Start MySQL from XAMPP.

  • Go to phpMyAdmin to check all databases are available & working.

  • Now start your any website project from localhost to check the MySQL database.

The Problem is solved !!

MySQL Error solved on XAMPP

  • Now you will see the problem is solved and the error message “Error: MySQL shutdown unexpectedly.” will not show again.
  • If you have any question on this issue please feel free to ask any question in the comments section.

You can read the details tutorials on the link bellow: Error: MySQL shutdown unexpectedly – Solution in 5 easy steps

You can also watch video tutorials to solve the problem:

[Solved] Error: MySQL shutdown unexpectedly

shafiq2410
  • 59
  • 3
3

go to : c: C:\xampp\mysql

Rename the folder "data" to "data_old" (you can use any name) Create a new folder "data" Copy the content of "backup" folder to the new "data" folder. Copy all content of "data_old" to "data" (skip those folder "mysql", "performance_schema", and "phpmyadmin") *** without remplacing the file in the destination (skip theses files)**

restart XAMPP and it will works

mir pekiro
  • 61
  • 6
3

Had the same issue.

STAEP 1

backup folder xampp/mysql/data (saved it as `xampp/mysql/_old_data`).

enter image description here

STAEP 2

Go to xampp/mysql/data and deleted all the files but not folders! With databases.

enter image description here

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.

DevWL
  • 14,674
  • 5
  • 82
  • 75
2

if you are using MariaDB you can try this:

  1. Go to mysql/data/
  2. Rename aria_log_control to aria_log_control_old
  3. Restart "Mysql"
Leo
  • 1,713
  • 3
  • 18
  • 23
2

Guys just make sure you dont have MySql Server installed. Because I have MySql server pre-installed and when I start mysql from xampp control panel some port conflicts are happening and its not working.. SO before starting the mysql from xampp control panel make sure mysql server is not installed. I use .net so I have installed mysql server in the Past. Uninstalling it solved my Problem....

Gvs Akhil
  • 1,850
  • 1
  • 15
  • 26
2

Go to task manager And search mysqld and right click and select END TASK and refresh XAMPP

2

What worked for me is (No File Delete):

  1. First I open Logs for MySql in XAMPP panel.
  2. At the end it says you are running another instance of mysqlid in port 3306
  3. I opened my task manager(Ctrl+Shift+Esc) then find mysqlid and End the task.
shibashis
  • 69
  • 1
  • 6
2

Go to C:\xampp\mysql\backup.

Copy all files.

Paste them into C:\xampp\mysql\data.

If Windows asks you to replace some files, replace them.

If your XAMPP Control Panes is active close it.

Go to C:\xampp and find xampp-control, run it.

Start Apache, start MySQL.


That's it.

Enjoy!

Ika
  • 166
  • 1
  • 3
  • This solution worked for me, accepted answer unfortunately didnt – pleshy Dec 04 '20 at 10:59
  • Thanks alot for your solution in here, I use your method is worked for me, I just want to comment one more step, we got to reuse old ibdata1 file from C:\xampp\mysql\data. This file can not replace otherwise database table will locked, thanks – Myint Thu Lwin Sep 21 '21 at 06:10
2

I had encountered the same issue, but all I had to do was close the XAMPP Control panel, go to the folder in which XAMPP is installed, find xampp-control.exe and run as administrator and then start the services.

enter image description here

Shishir
  • 186
  • 2
  • 7
2

follow these steps:-

  1. Go into C:\xampp\mysql

  2. Rename data folder by data_old

  3. Create a new folder empty data folder

  4. Copy all files from data_old and paste them into the data folder

  5. Copy all files from the backup folder and paste them in the data folder and replace all files

  6. Copy ibdata1 files from data_old and paste and replace them in the data folder.

  7. Restart Server

All the best!!

A.Jain
  • 60
  • 8
2

Xampp stop Instantly after start.

copy all files and folder from C:\xampp\mysql\backup and paste into C:\xampp\mysql\data.

enter image description here

Talha Rafique
  • 3,547
  • 1
  • 9
  • 9
1

In my case in which I synced my mysql data and htdocs to dropbox, I just needed to delete the conflicted files in mysql/data folder and subfolders. The conflicted files can be identified by its names, dropbox will tell you that. It has solved the problem for me.

maurisrx
  • 319
  • 4
  • 9
1

For me I quit Skype, which was occupying port 80, then Apache ran happily on port 80, than I ran Skype and it picked another port this time.

Tiffany
  • 611
  • 13
  • 29
sudhanshu
  • 403
  • 8
  • 22
1

Make sure the system time is correct. Mine was set to the year 2040 somehow, correcting the date solved the problem.

user247702
  • 22,915
  • 14
  • 108
  • 152
shakee93
  • 4,396
  • 2
  • 25
  • 30
1

i comment this statement in mysql/bin/my.ini

'innodb_additional_mem_pool_size=2M'

and it solve my problem. than you everyOne

Boston Kenne
  • 720
  • 10
  • 13
1

For me, the problem was:

I used to hibernate my PC instead of shutting down due to the scale of the project. I was lazy enough to reopen all programs.

Before trying anything else, I recommend you to do the following simple things. Otherwise, you will be messed up your MySQL server.

  1. Open your task manager and End the XAMPP process.
  2. Re-run the XAMPP application as Administrator.

If not works,

  1. Save all unsaved programs and restart the PC.
  2. Run XAMMP as administrator.

Also, make sure to check 3306 & 5040 ports. These two ports are required to run MySQL on default settings.

Check @Ryan Williams answer to find of why it's good to run XAMPP as administrator.

Varuna
  • 138
  • 2
  • 15
1
0.cntr+alt+delet
1.end task mysqld
2.Restart mysql.

mirazimi
  • 620
  • 7
  • 10
1

I literally deleted every file from c:\xampp\mysql\data\ except my.ini and it works

ticky
  • 353
  • 2
  • 12
  • Sure it works but some tables does not exists after this operation. My opinion backup data folder to zip file or another path. then try this operation. After completed restore ibdata1 and ib_logfile0 and ib_logfile1 now it works and all tables restored Actions: Server = Xampp Application = Voyager admin (Laravel) – Nijat Aliyev Mar 25 '20 at 20:15
1

first of all, make a backup file of your database C:\xampp\mysql\data copy this file and past it somewhere in your pc. After this open, the data file and also open the XAMPP server try to delete the files step by step one by one after deleting each file try to run the MySQL server after deleting a single file as shown in the screenshot thus your databases won't delete. if the file deletion does not work then try to copy the same files from the backup folders and repeat this until it works... this is time taking but this worked for me I have solved this in 20 minutes. enter image description here

1

STOP! Please do NOT delete ibdata1 file!

Deleting this file is like playing a Russian roulette with your databases, it could work and restablish everything, but also, probably could leave unusable every database you have.

Instead, first try using the MySQL backup folder which is included with XAMPP. So do the next:

Rename the folder mysql/data to mysql/data_old (you can use any name) Create a new folder mysql/data Copy the content that resides in mysql/backup to the new mysql/data folder 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) Finally copy the ibdata1 file from mysql/data_old and replace it inside mysql/data folder Start MySQL from XAMPP control panel

Hasitha
  • 59
  • 11
1

I faced the same issue. MySQL stops as soon as I turn it on.

In the logs it said:-

10:31:21 [mysql] Problem detected! 10:31:21 [mysql] Port 3306 in use by "Unable to open process"! 10:31:21 [mysql] MySQL WILL NOT start without the configured ports free!
10:31:21 [mysql] You need to uninstall/disable/reconfigure the blocking application
10:31:21 [mysql] or reconfigure MySQL and the Control Panel to listen on a different port

I stopped the running service on port 3306 wamp(in my case), and it worked fine after that. Changing the port in config settings should also work.

YW!

csgeek
  • 471
  • 4
  • 8
1

Simple solution

Rename below files in xampp\mysql\data folder

 ib_logfile0
 ib_logfile1

Or any such logfiles to

 ib_logfile0.bak
 ib_logfile1.bak

And now start mysql from xampp control.

Rahul Kaushik
  • 1,436
  • 8
  • 16
1

I also get the same issue. Solution was kill process Find the PID for port (3306)

netstat -a -n -o | find "3306"

You will see everything you need.

0.0.0.0:3306           0.0.0.0:0              LISTENING       8120   TCP    
0.0.0.0:33060          0.0.0.0:0              LISTENING       8120   TCP    
[::]:3306              [::]:0                 LISTENING  8120   TCP    
[::]:33060             [::]:0                 LISTENING  8120

PID is 8120

Next run the following command

taskkill /PID 8120 /F

Start MySQL again. It will be fine. Happy cording.

Priyantha
  • 4,361
  • 5
  • 24
  • 41
0

Config->Apache->Open httpd.conf. search for Listen or 80,update listen port to 8081 save and restart server. Oh and shutdown Skype if you have it.

Mihai
  • 24,788
  • 7
  • 64
  • 78
  • 2
    Yeah, that fixed it. I swear I reinstalled before posting that, but I guess not. Thanks :) – Austin Aug 03 '13 at 21:01
0

For this, you need to click on the x option under Modules Services and make MYSQL services installed. Then start the services. Here you go.

Fahad Naeem
  • 504
  • 6
  • 15
0

If the crash message is "mysql.exe has stopped working". Just run xampp-control.exe as administrator will solve your problem instantly.

0

If any of the things above do not work, make a back of Xampp directory and reinstall Xampp. That surely works!

0

Rename below files from mysql/data ib_logfile0 ib_logfile1 ibdata1

my.cnf innodb_buffer_pool_size to 200M as per your ram innodb_log_buffer_size to 32M

Restart your apache server

hope it helps you

insoftservice
  • 800
  • 6
  • 14
0

I solved! deactivate UAC with msconfig before to install xampp

enter image description here

Joel Meza Baca
  • 612
  • 9
  • 12
0

That's the more precise answer and worked for me!!!! ! 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. as mentioned above by Ryan Williams.

zaffar
  • 591
  • 5
  • 13
0

If you are getting this type of error then

Create a Back up your mysql folder from C:\xampp\mysql. Then go to C:\xampp\mysql\backup Copy all the files and paste it into C:\xampp\mysql\data.

Then from your old backup folder see for ibdata1 file you can find it in C:\xampp\mysql\data. Copy this file and paste in into C:\xampp\mysql\data.

Now restart xampp and it should work.

Jay Momaya
  • 1,548
  • 16
  • 27
0

There are a number of things I've tried. This is the 2nd time this has happened to me. On my first time, I've to reinstall my xampp. And on the third day, mysql crashed again. I've tried everything I found on the internet. Like, innodb_flush_method=normal in my.ini file and deleting ibdata1, ib_logfile1, ib_logfile0 files, and others but none of these works. So later I tried to run xampp with admin privilege and install apache and mysql as a service as it was instructed on xampp control panel itself. After starting mysql, I read error-log again and from there I came to know that one of my databases is responsible for this. That database file won't let mysql start. So I deleted everything in the data folder and then in cmd I navigated to C:/xampp/mysql/bin path and ran these commands:

mysqld --initialize

mysql_install_db

and mysql started running again. But my databases and data are lost.

Nirav Chavda
  • 101
  • 3
  • 7
0

If none of the solutions listed here didn't work for you just like me, then

  1. Go to your task manager.
  2. Go to the Services tab.
  3. Find Service named "MySQL80".
  4. Right-click on it and select "stop".
  5. Go back to XAMPP control panel and start the MySQL service.

It worked for me.

preet shah
  • 37
  • 1
  • 9
0

If none of the deletion of files work then probably your mysql service is not running. Go to services.msc and start mysql service

Rudr Thakur
  • 172
  • 1
  • 9
0

enter image description hereI also had this problem when i get this error , go xampp->mysql->data then delete all other files without folder , do not delete folders , then run xampp and start mysql

0
Error: MySQL shutdown unexpectedly

This is the best answer 

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)Start MySQL from XAMPP control panel
0

If you do not need data in the corrupt table, you can drop it by first discarding the tablespace:

ALTER TABLE sakila.actor DISCARD TABLESPACE;

after that you can drop the table itself:

DROP TABLE sakila.actor;

In case the first step is not working, first replace actor.ibd file with a copy from an empty table with the same structure.

Source

Bojan Hrnkas
  • 1,440
  • 15
  • 22
0
# The MySQL server
default-character-set=utf8mb4
[mysqld]
skip-grant-tables // Palace this line here 
port=3306
socket="C:/xampp/mysql/mysql.sock"
basedir="C:/xampp/mysql"
tmpdir="C:/xampp/tmp"
datadir="C:/xampp/mysql/data"
pid_file="mysql.pid"
# enable-named-pipe
key_buffer=16M
max_allowed_packet=1M
sort_buffer_size=512K
net_buffer_length=8K
read_buffer_size=256K

Open my.ini file from C:\xampp\mysql\data skip-grant-tables place this line before port and restart and it working

0

None of the solutions above are not working. It's working only temporarily. After a few days, we are facing the same issue again & again. I've lost all of my DBs on each and every time.

I don't know the exact solution. But, I am doing the 3 simple steps again & again.

  1. Rename the folder c:\xampp\mysql\data to c:\xampp\mysql\data_old (you can use any name).
  2. Create a new "data" folder c:\xampp\mysql\data
  3. Copy all your database folders that are in mysql\data_old to mysql\data

then Start MySQL from the XAMPP control panel.

SOLVED!: I solved it using this method:

Open shell from from control panel and start mysql with this command:

mysqld –-console –-skip-grant-tables –-skip-external-locking

Open another shell from the control panel and repair the database with this command:

mysqlcheck -r --databases mysql --use-frm

Stop mysql, close shells, and restart mysql normally.

Refer: https://stackoverflow.com/a/60576807/1662058

Thirsty Six
  • 263
  • 5
  • 13
-1
  1. Copy all files from xampp/mysql/backup/ then paste into /xampp/mysql/data/
  2. Restart mysql.
-1

Fixed it by reinstalling the Xampp.

If you don't want to go through all the technical stuff that the other proposes.

Back up the htdocs folder then uninstall Xampp, it will ask you if you want to retain the htdocs folder, opt-out. Completely uninstall, remove the remains. The install again, copy back your backed-up htdocs folder.

you're done.

designdust
  • 79
  • 1
  • 4
  • The MySQL database was corrupted. Perhaps files were copied around. Somehow two different tables ended up with the same tablespace id and that is not possible during normal MySQL operation. By removing XAMPP you removed MySQL and then you reinstalled it, which fixed the corruption. It would be possible to remove the MySQL data directory and re-initialize it, but uninstalling and reinstalling did the same. – Justin Swanhart Oct 23 '20 at 03:11
  • I think mysql database will be removed in this case. Someone let me know. – Zawad Nov 19 '20 at 08:39
-2
  1. go to Task manager (by clicking into: ctrl + alt +delete);
  2. find : processes
  3. look for: mysql
  4. select and cick "end task"
Dharman
  • 26,923
  • 21
  • 73
  • 125
mir pekiro
  • 61
  • 6