2、网上查了,都说如果是 linux 需要执行 mysql_install_db;如果是Windows需要拷贝 user.frm user.MYD和user.MYI
3、不过,http://serverfault.com/questions/291126/mysql-fatal-error-cant-open-and-lock-privilege-tables-table-mysql-host-doe
这里面有人建议使用 mysqld --initialize
执行了下,报错:
C:Program FilesMySQLMySQL Server 5.7in>mysqld --initialize
2016-12-20T04:33:22.298853Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is
deprecated. Please use --explicit_defaults_for_timestamp server option (see doc
umentation for more details).
2016-12-20T04:33:22.298853Z 0 [Warning] "NO_ZERO_DATE", "NO_ZERO_IN_DATE" and "E
RROR_FOR_DIVISION_BY_ZERO" sql modes should be used with strict mode. They will
be merged with strict mode in a future release.
2016-12-20T04:33:22.298853Z 0 [Warning] "NO_AUTO_CREATE_USER" sql mode was not s
et.
2016-12-20T04:33:22.303853Z 0 [ERROR] --initialize specified but the data direct
ory has files in it. Aborting.
2016-12-20T04:33:22.304853Z 0 [ERROR] Aborting
4、因为都是测试数据,我就直接把 datadir (我的是D:MysqlData) 文件夹给删了。再次执行mysqld --initialize
C:Program FilesMySQLMySQL Server 5.7in>mysqld --initialize
5、启动服务(如果没有安装服务的话需要先 执行 mysqld --install)
C:Program FilesMySQLMySQL Server 5.7in>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
这种方法比起拷贝 user. 文件的要简单,不过需要清除所有数据,适合在自己的测试环境上使用。