Unable to start mysql via XAMPP - mysql\db crashed - mysql

I have successfully been using XAMPP on my windows 10 PC to run a website that I am working on locally until today.
When I try to start MySQL, it fails. The error logs state:
mysqld.exe: Table '.\mysql\db' is marked as crashed and last (automatic?) repair failed
Fatal error: Can't open and lock privilege tables: Table '.\mysql\db' is marked as crashed and last (automatic?) repair failed
As I try to fix this, I attempted the following:
mysqlcheck --repair --use-frm --all-databases
but this gives me the following error:
Got error: 2002: Can't connect to MySQL server on 'localhost' (10061) when trying to connect
Which I guess makes sense because the mysql service isnt able to run.
I have also tried running the following from this directory: c:\xampp\mysql\data. Doing this results in an error saying 'db' doesnt exist.:
myisamchk -r db
I noticed that i have a db.MAD file that is rather large 174,616K, so not sure if that is the problem.

I ran into the same problem here is what I did:
Find and open the 'my.ini' file with Notepad. (Mine is at c:\xampp\mysql\bin\my.ini )
Insert 'skip-grant-tables' in the 'my.ini' file on a new line following the label '[mysqld]' and save. You will remove this after the problem is fixed.
Now mySQL you can start XAMPP from the control panel.
Start phpMyAdmin from your browser and select the table 'db' from the database 'mysql'
(Select 'mysql' from left panel then check 'db' in right hand panel).
Beneath from the 'With selected' dropdown, run 'analyze' (it should say that it is corrupted). Then select again and run 'repair table'.
Find the 'my.ini' file again and open with Notepad.
Remove 'skip-grant-tables' in the 'my.ini' file and save.
Problem should be fixed and you should be able to start XAMPP normally which will start MySQL normally.

Related

Error: MySQL shutdown unexpectedly. XAMPP, how to repair a corrupt table

I have been researching this issue for 2 days now and all the questions and answers do not solve my problem.
Found! in the mysql_error.log after running it several times:
2020-01-06 16:34:11 0 [ERROR] mysqld.exe: Table '.\mysql\user' is
marked as crashed and last (automatic?) repair failed
2020-01-06 16:34:11 0 [ERROR] Fatal error: Can't open and lock privilege tables:
Table '.\mysql\user' is marked as crashed and last (automatic?)
repair failed
So now I see the issue after numerous times trying to start MySQL and reviewing the log, this time I finally see the "user" table is corrupt.
Can anyone advise how to repair this?
First, from XAMPP control panel, open "Config" [mysql] and add the
following line under [mysqld] = innodb_force_recovery = 1
then do the following:
Open shell from control panel and start mysql with this command:
mysqld –-console –-skip-grant-tables –-skip-external-locking
Open another shell from control panel and repair database with this command:
mysqlcheck -r --databases mysql --use-frm
Stop mysql, close shells and restart mysql normally.
IF it doesn't work then change innodb_force_recovery = 2 and repeat process, and again if that doesn't work, change to 3, etc... up to 4
You can find this answer useful
I saw this answer in an unclear form here on stackOverflow which helped me, hope this answer helps too
1 - open the directory "c:/xampp/mysql/data" and remove the folder "mysql"
2 - now you will copy the "mysql" folder from "c:/xampp/mysql/backup" and then paste it in the "c:/xampp/mysql/data" directory
Hope this answer helps!
As XAMPP forcefully shutsdown the database process sooner or later this is bound to happen.
Considering you are running windows (from the \ I deduce you are) there are a couple of steps you could try to repair this.
rename c:\xampp\mysql\data to something else (data_YYMMDD)
copy c:\xampp\mysql\backup to c:\xampp\mysql\data
try to see of MariaDB starts (it should) and stop it.
copy over InnoDB folders from c:\xampp\mysql\data_YYMMDD to c:\xampp\mysql\data
run c:\xampp\mysql\mysqlcheck.exe --auto-repair --all-databases -uroot
Btw. any user accounts you created will be lost and will have to be recreated.

MYSQL no longer starting on Mac with MAMP

Up until today MYSQL was working OK for months with 2 MAMP Drupal localhost builds.
But now MYSQL no longer loads.
When opening MAMP the Apache Server starts,
whereas the MYSQL Server does not start.
This means the "Open WebStart page" option is greyed over and the Drupal path that would normally load the site just displays an error.
Using Terminal, if I run:
which mysql
the response is:
/Applications/MAMP/Library/bin/mysql
But if I try to login into MYSQL via Terminal:
mysql -u (myuser) -p
I am prompted for the password, but after entering correct password I receive:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/Applications/MAMP/tmp/mysql/mysql.sock' (2)
I checked that path, and there is no mysql.sock file there. In that directory there is just one file titled .dummy that has no content in it.
Some forums relating to the same error suggest I check and stop any other running MYSQL instances, but I don't appear to have any.
For example I ran:
ps -ef | grep mysql
And I just receive this:
501 11212 10699 0 12:31pm ttys000 0:00.00 grep mysql
I don't entirely understand that response, but it looks like there is nothing running that I can 'kill'.
Also, if I try things like:
sudo service mysql start
I am prompted for my Mac user password, which I enter, but I am then given the error:
sudo: service: command not found
Any help here would be greatly appreciated.
EDIT: I ran:
mysqld
And received a lot of information! Too long to paste here,
but some things I noticed were:
2019-02-14T03:01:33.211495Z 0 [Note] --secure-file-priv is set to NULL.
Operations related to importing and exporting data are disabled
I don't know how to address the above, but it sounds like it's not helping the situation?
Further on from there, the first 'warning' from the list was:
[ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
I followed that advice and ran:
mysql_upgrade
and received this error:
mysql_upgrade: Got error: 2002: Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2) while connecting to the MySQL server
Upgrade process encountered error and will not continue.
Any ideas as to how to fix that?
Some other errors I noticed are:
[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
[ERROR] Fatal error: Failed to initialize ACL/grant/time zones structures or failed to remove temporary table files.
[ERROR] Aborting
followed by a lot of lines of "shutting down plugin...(various)..." that ended in:
mysqld: Shutdown complete
Again, I am completely lost here?
After hours of trying out suggestions from various forum threads, such as:
Creating my.cnf files; or
Adjusting the MAMP php.ini file with extra code, or
Reinstalling MAMP again,or
Dumping the "ib_logfile.." files from the MAMP/db/mysql57 directory,
The only thing that finally resolved this for me was:
I suddenly remembered I copied all my working files to a backup.
so I checked the backup directories for MAMP/db/mysql57 and noticed there was a lot of content in there that for some reason was now missing from my live version,
so I deleted everything in the current MAMP/db/mysql57 directory and pasted all the backup items in.
Suddenly MAMP's MYSQL server lights up, the Startup page auto loads into my browser and I can run drush commands in my CLI and load the Drupal CMS again.
Happy Days!

Upgraded WampServer, now can't start MySQL

I moved my WampServer www and SQL/data to Dropbox, and WampServer was working fine like this.
I noticed I was using an old version of WampServer on my desktop, while using the latest version of WampServer on my laptop.
I uninstalled WampServer on my desktop, and installed wampserver3.0.6_x86_apache2.4.23_mysql5.7.14_php5.6.25-7.0.10 on my desktop.
I edited my.ini: datadir="D:/Dropbox/WAMP/SQL"
When I load http://localhost/phpmyadmin in my browser, I attempt to login, but receive the error:
No connection could be made because the target machine actively
refused it. — The server is not responding (or the local server's
socket is not correctly configured).
If I check C:\wamp\logs\mysql.log I see:
wampmysqld: Table 'mysql.plugin' doesn't exist
2017-04-15T11:43:23.372042Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2017-04-15T11:43:23.373043Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-04-15T11:43:23.378046Z 0 [Warning] Failed to open optimizer cost constant tables
2017-04-15T11:43:23.384551Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2017-04-15T11:43:23.386553Z 0 [ERROR] Aborting
If I look in the folder D:\Dropbox\WAMP\SQL\data\mysql, I see the files:
plugin.frm
plugin.MYD
plugin.MYI
user.frm
user.MYD
user.MYI
If I run the following in a cmd window:
C:\wamp\bin\mysql\mysql5.7.14\bin> mysql_upgrade.exe
I receive the error:
mysql_upgrade: Got error: 2003: Can't connect to MySQL server on
'localhost' (10061) while connecting to the MySQL server Upgrade
process encountered error and will not continue.
If I go to System Tray > Wamp > MySQL > Version, I see only one option: 5.7.14.
If I try to start MySQL from Wamp icon, or services.msc, it won't start, and the errors above repeat.
Update: if I run http://localhost/phpmyadmin on my laptop, which uses www and SQL data in Dropbox too, phpMyAdmin produces no error, and detects the databases fine, and lists them down the left hand side.
What do I need to do from here?

After install, mySQL doesn' start (windows10, source install)

I'm installing Apache server, php, and MySQL on Windows10.
First two was successful but MySQL has a problem.
I installed MySQL into C:\mysql-5.7.10-winx64, and changed my.ini like this
basedir = C:/mysql-5.7.10-winx64
datadir = C:/mysql-5.7.10-winx64/data
port = 3306
I succeeded install but if I try to start, it shows like below
C:\Windows\system32>net start mysql
The MySQL service is starting.
The MySQL service could not be started.
The service did not report an error.
More help is available by typing NET HELPMSG 3534.
However, if I check Computer Management>Event Viewer>Custom Views>Summary page events, it tells me "failed to set datadir to C:\mysql-5.7.10-winx64\data\"
If I make data folder manually, error message changed to
Can't open the mysql.plugin table
Please run mysql_upgrade to create it.." and some files are created in data folder
I tried to upgrade by typing mysql_upgrade but it failed.
mysql_upgrade: Got error: 2003: Can't connect to MySQL server on 'localhost' (10061) while connecting to the MySQL server. Upgrade process encountered error and will not continue.
How can I solve this issue?
Clear the "data" directory, then run command mysqld --initialize, and the command net start mysql, bingo!
1.For the error,
2003: Can't connect to MySQL server on 'localhost' (10061) while connecting to the MySQL server. Upgrade process encountered error and will not continue.
I ran the cmd as administrator and then go to \Program Files\MySQL\MySQL Server 5.7\bin\, and run
mysqld install
2.For the error,
C:\Program Files\MySQL\MySQL Server 5.7\bin>net start mysql
The MySQL service is starting.
The MySQL service could not be started.
The service did not report an error.
More help is available by typing NET HELPMSG 3534.
Try
mysqld --initialize
and then
net start mysql
Thanks to Athan's answer. Those combination worked for me.
I also had the same problem and I wasted hours solving the issue, but in the end this worked.
Go to you C:\ProgramData\MySQL\MySQL Server 5.7 and copy the my.ini file from there.
Go to C:\Program Files\MySQL\MySQL Server 5.7 and paste it there.
Open cmd and run net start mysql
It would work like a charm.
Explanation:
MySQL couldn't find my.ini, therefore tried to create data in Program Files... where it had no rights to do so, therefore it says access denied every time you run it.
This is old but I was running into the same problem you were seeing. I thought I'd share this answer for anyone looking. I created the data directory as you did initially and tried to start the service and got "Can't open and lock privilege tables: Table mysql.user doesn't exist." I then deleted the contents of the data directory and instead initialized the data directory by running the following command from the bin folder.
mysqld --initialize [with random root password]
mysqld --initialize-insecure [without random root password]
I had the same error, after checked this document: https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization.html
I just clear data directory and add the --console option to initialize:
bin\mysqld --defaults-file=C:\my.ini
--initialize --console
Hope this help
MySQL Server can either be run as a Program or as a Service. You cannot run both. You should stop 'mysqld' Server Program before starting 'mysqld' Server as Service.
The 'mysqld' Server Program can be stopped either by typing
'CTRL + c' or by issuing
'mysqladmin -u root -p shutdown' command and issue the password when prompted.
You need download from https://dev.mysql.com/downloads/mysql/ previous GA versions, and after that copy directory "data" to your new mysql or outher directory what you write in configfile my.ini in directory mysql-"version" .
For your error, main cause is in your my.ini setting.
Since you are installing MySQL on Windows, you should define path like:
basedir = C:\\mysql-5.7.10-winx64
datadir = C:\\mysql-5.7.10-winx64\\data
These slashes must be doubled.
Then start your MySQL service again. I guess this time would work.
And here is official document from MySQL.
This saved my life,
Just turn off the windows firewall and Give he port number correctly as 3306 as default, then restart MYSQL server . After that turn on the windows defender firewall
Just work it fine.
Looks like my solution is not added yet,
I've installed mysql80 , edited my.ini in windows notepad and got the same error like topic author "... NET HELPMSG 3534." when I start mysql service,
and my issue was in extra bytes added by notepad at the begining (EB BB BF) on my.ini, when I edited (added the same changes) my.ini in other editor everything worked fine.

Xampp manager on Mac OSX, recently the mysql server stopped starting

I tried everything, changing the port no. and all but it still did not start I had to end the mysql process using the activity monitor and now the tables wont respond. When I click the name it shows an error message: #1146 table 'table_name' doesn't exist!
My past projects will be wasted if they don't respond and I had forgotten to export the databases.
you can run this command to repair any database you have:
mysqlcheck -u mysql_username -p database_name
but if you see this error after running this:
Error: Table 'database_name.table_name' doesn't exist
you should drop your damaged table, all details can you find through this link