简体   繁体   中英

Fix MySQL Server data directory

I have a very weird Problem on Windows 10 with MySQL Server 8:

I could not start the mysql server or service with mysqld or net start mysql as mysql reported a missing data directory (it could not write a 'test file'). It is/was looking in C:\\Program Files\\MySQL\\MySQL Server 8.0 .

After some googling I could start the mysql server after running mysqld --initialize , which did create a data folder beneath C:\\Program Files\\MySQL\\MySQL Server 8.0 and reseted the password somehow. Unfortuneatly, all my databases are gone after I connect to the (I think so) newly initialized mysql server.

After some more googling I found, that there is the following directory on my PC: C:\\ProgramData\\MySQL\\MySQL Server 8.0 ... and voilà .. inside that Data directory there are folders with names of my (lost) databases. So I am pretty sure, that my data is in there.

But how do I set up the mysql server to use this correct data/settings whatever. I do not want to use a newly initialized mysql server.

I tried copying the folders from C:\\ProgramData\\MySQL\\MySQL Server 8.0 to C:\\Program Files\\MySQL\\MySQL Server 8.0 but with no luck. One time the server could not be started, on the other occasion the data was just ignored. I also tried to copy a my.ini to C:\\ProgramData\\MySQL\\MySQL Server 8.0 and change the datadir entry beneath [mysqld] -> No luck.

Any help is appreciated.

UPDATE:

The following errors and warnings appear in my ".err" file:

2020-03-11T19:21:10.658537Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.

2020-03-11T19:21:10.659813Z 0 [System] [MY-010116] [Server] C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqld.exe (mysqld 8.0.19) starting as process 4040

2020-03-11T19:21:11.340219Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.

2020-03-11T19:21:11.358861Z 0 [Warning] [MY-013143] [Server] Column count of mysql.user is wrong. Expected 51, found 49. The table is probably corrupted

2020-03-11T19:21:11.359562Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.db. The table is probably corrupted!

2020-03-11T19:21:11.360108Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.tables_priv. The table is probably corrupted!

2020-03-11T19:21:11.360680Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.tables_priv. The table is probably corrupted!

2020-03-11T19:21:11.361259Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.columns_priv. The table is probably corrupted!

2020-03-11T19:21:11.361881Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.procs_priv. The table is probably corrupted!

2020-03-11T19:21:11.362474Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.procs_priv. The table is probably corrupted!

2020-03-11T19:21:11.363076Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.proxies_priv. The table is probably corrupted!

2020-03-11T19:21:11.363713Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.proxies_priv. The table is probably corrupted!

2020-03-11T19:21:11.364309Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.proxies_priv. The table is probably corrupted!

2020-03-11T19:21:11.364908Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.role_edges. The table is probably corrupted!

2020-03-11T19:21:11.365505Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.role_edges. The table is probably corrupted!

2020-03-11T19:21:11.366123Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.default_roles. The table is probably corrupted!

2020-03-11T19:21:11.366774Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.default_roles. The table is probably corrupted! 2020-03-11T19:21:11.367391Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.global_grants. The table is probably corrupted!

2020-03-11T19:21:11.368010Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.password_history. The table is probably corrupted! 2020-03-11T19:21:11.369081Z 0 [ERROR] [MY-013139] [Server] Cannot load from mysql.global_grants. The table is probably corrupted!

2020-03-11T19:21:11.369779Z 0 [ERROR] [MY-010952] [Server] The privilege system failed to initialize correctly. For complete instructions on how to upgrade MySQL to a new version please see the 'Upgrading MySQL' section from the MySQL manual.

2020-03-11T19:21:11.371103Z 0 [ERROR] [MY-010119] [Server] Aborting

2020-03-11T19:21:12.355716Z 0 [System] [MY-010910] [Server] C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqld.exe: Shutdown complete (mysqld 8.0.19) MySQL Community Server - GPL.

I tried to run mysql_upgrade , which just tells me, that it cannot be run because the upgrade tool is deprecated..

One folder above the data dir is a my.ini file, there is the main configuration file of mysql.

Mysql finds this file by starting the service with

"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe" --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" MySQL80

See if you have this option correctly

datadir=C:/ProgramData/MySQL/MySQL Server 8.0/Data

I could solve my problem. For some reason the deprecated upgrade tool was integrated into the server tool. I had to run

mysqld --defaults-file="C:/ProgramData/MySQL/MySQL Server 8.0/my.ini" --upgrade=FORCE

this was not all to the problem. For some other unknown reasons, my password for the root user was not accepted anymore. Threfore I had to reset my password by this procedure: Chapter 4 Resetting the Root Password: Windows Systems

Summary: Fixing my problem by

  1. Using the --defaults-file parameter of mysqld to point to the correct my.ini file
  2. Fixing the path to the correct data dir in the my.ini file
  3. running upgrade on server by the parameter --upgrade=FORCE
  4. resetting the password of my mysql user

I still have no idea, why this desaster happened, anyway....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM