最新消息:20210917 已从crifan.com换到crifan.org

【基本解决】如何恢复Mac中mysql中的mysql表

Mac crifan 1881浏览 0评论

在Mac本地中mysql中,刚才不小心,drop掉了mysql表:

<code>➜  AliyunRdsMysql mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 34
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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&gt; show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| your_db          |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.02 sec)

mysql&gt; drop database mysql;
Query OK, 31 rows affected, 2 warnings (0.18 sec)

mysql&gt;
</code>

现在想要尝试看看能否恢复。

-》否则mysql表中保存的,用于mysql的管理信息,包括用户等信息,都丢失了,就不能正常使用了。

mysql restore mysql database

mysql restore mysql table

MySQL restore: How to restore a MySQL database from a backup | alvinalexander.com

Restoring a MySQL table back to the database – Stack Overflow

mysql restore default mysql database

How to recover/recreate mysql’s default ‘mysql’ database – Stack Overflow

MySQL – recreate default mysql database – Server Fault

Quickly resetting a local MySQL database from the command line [Updated] | Jeff Geerling

How can I reset my MySQL database to default?

此处没有要恢复的数据库了,所以直接去试试重新初始化

<code>mysqld --initialize
</code>

结果出错:

【已解决】Mac中mysqld去重新初始化mysql出错:mysqld Can’t create directory /usr/local/mysql-5.7.22-macos10.13-x86_64/data/ Errcode 17 File exists

但是进去后:

<code>➜  mysql git:(master) ✗ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 39
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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&gt; show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)

mysql&gt;
</code>

发现没有了,之前还存在的,默认的mysql数据库了啊。

而且很搞笑的是:

root用户的密码,还是之前自己设置的,而不是上面刚生成的临时的密码。

所以,暂时懒得继续研究了。先能用Mac中本地的mysql再说。后续有问题再说。

【总结】

此处就是:

<code>mysqld --initialize
</code>

去重新初始化数据库

-》但是并没有看到希望看到的:

重置后,会生成mysql数据库。

而且好玩的是:

重置后,root用户的密码,都不是重置生成的临时密码,而还是我之前自己设置的密码。

暂时不管了,先能用mysql,后面有问题再说。

【后记】

后来出了:

【已解决】Mac中mysql中创建数据库出错:ERROR 1006 HY000 Can’t create database errno 230174752

最终是,完全删除旧的,重新安装,重新保证data目录及子目录有权限,以及删除sock,才保证mysql可以正常启动的。

又经历重置密码,才得以正常使用mysql,才能去新建数据库。

转载请注明:在路上 » 【基本解决】如何恢复Mac中mysql中的mysql表

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.200 seconds, using 23.40MB memory