目录
前言
话说某天,突然笔记本上的mysql workbench CE6.3不知道是否升级失败还是什么原因,反正在workbench上所有的库与schema都丢失,然后那个时候在使用sonarqube和搭建ansible,一摊事情没搞定又蹦出另一摊。
解决方案
1、首先在windows搜索到原本的数据库配置文件my.ini。
C:\ProgramData\MySQL\MySQL Server 5.7\my.ini
2、然后以管理员身份在MySQL安装目录的 bin 目录下执行命令:
mysqld --initialize --console
执行完成后,会打印 root 的临时初始默认密码(如下图)
2019-04-02T15:01:41.317617Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-02T15:01:43.622121Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-04-02T15:01:44.181330Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-02T15:01:44.383691Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 3ad2952f-5558-11e9-a8e3-005056c00001.
2019-04-02T15:01:44.449846Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-04-02T15:01:44.463592Z 1 [Note] A temporary password is generated for root@localhost: XXXXXXXXXXXXX
3、安装服务
在MySQL安装目录的 bin 目录下执行以下命令并得出以下安装成功的结果。
mysqld --install [服务名] --defaults-file="[ini文件绝对路径]"
(如mysqld --install orginalMysql --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.7\my.ini"
Service successfully installed.
4、运行服务
继续在bin目录下,运行以下命令并得出以下服务成功启动的结果。
net start [服务名]
如 net start originalMysql
originalMysql 服务正在启动 ..
originalMysql 服务已经启动成功。
5、登录成功
C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -u root -p
Enter password: **********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.14-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql>
mysql>
mysql>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| application |
| gun |
| mysql |
| performance_schema |
| sakila |
| sonar |
| sys |
| world |
| xwiki |
+--------------------+
10 rows in set (0.10 sec)