最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Mac本地搭建mysql数据库并导入已备份出的sql文件

Mac crifan 4363浏览 0评论

折腾:

【已解决】pymysql连接出错:pymysql.err.OperationalError 2003 Can’t connect to MySQL server on mysql.rds.aliyuncs.com Errno 61 Connection refused

期间,已经:

【已解决】把阿里云上只能内网访问的mysql数据库备份到Mac本地

现在需要继续去想办法把备份出来的数据库文件,导入到本地的mysql。

但是本地需要先去安装对应的mysql。

然后安装的版本,进来和服务器端一致。

先去看看服务器中的mysql的版本:

数据库类型:MySQL 5.7

所以本地也去在Mac中安装5.7的mysql,并正常能访问:

【已解决】Mac本地安装5.7版的MySQL数据库并正常登录和访问mysql

然后去命令行中,把之前备份好的数据导入到本地的Mysql中

mysql 恢复

MySQL 备份和恢复 | iMySQL | 老叶茶馆

解锁MySQL备份恢复的4种正确姿势 – MySQL – DBAplus社群——围绕数据库、大数据、PaaS云,运维圈最专注围绕“数据”的学习交流和专业社群

mysql备份与还原 – gxcherie – 博客园

总结:MySQL备份与恢复的三种方法-Free Linux, Share Linux-51CTO博客

mysql 导入 sql

linux命令行下导出导入.sql文件 – CSDN博客

<code>➜  ~ pwd
/Users/crifan
➜  ~ /Users/crifan/dev/dev_root/company/xxx/projects/NLP/AliyunRdsMysql
➜  AliyunRdsMysql ll
total 1928
-rw-r--r--@ 1 crifan  staff   834K  4 26 10:58 aliyun_rds_xxx_mysql_dump.sql
-rw-r--r--@ 1 crifan  staff    90K  4 26 10:56 aliyun_rdsxxx_mysql_dump.sql.gz
➜  AliyunRdsMysql pwd
/Users/crifan/dev/dev_root/company/xxx/projects/NLP/AliyunRdsMysql
➜  AliyunRdsMysql mysql -u root -p xxx &lt; aliyun_rds_xxx_mysql_dump.sql
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
➜  AliyunRdsMysql mysql -u root -p xxx &lt; aliyun_rds_xxx_mysql_dump.sql
Enter password:
ERROR 1049 (42000): Unknown database 'xxx'
➜  AliyunRdsMysql
</code>

结果需要先创建对应数据库才可以。

<code>➜  AliyunRdsMysql mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
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; create database xxx;
Query OK, 1 row affected (0.01 sec)

mysql&gt; exit
Bye
➜  AliyunRdsMysql mysql -u root -p xxx &lt; aliyun_rds_xxx_mysql_dump.sql
Enter password:
</code>

再去用sequel进去看看

就可以看到数据了:

【总结】

总体流程就是:

1.先去安装

【已解决】Mac本地安装5.7版的MySQL数据库并正常登录和访问mysql

确保正常能用root账号,不仅是终端shell,还要mysql工具,比如Sequel,都能连接和管理mysql。

2.先建一个空的数据库

<code>mysql -u root -p
&gt; create database your_database;
&gt; exit
</code>

3.再去导入数据即可

<code>mysql -u root -p your_database &lt; your_dump_out_sql_file.sql
</code>

即可。

转载请注明:在路上 » 【已解决】Mac本地搭建mysql数据库并导入已备份出的sql文件

发表我的评论
取消评论

表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.169 seconds, using 22.11MB memory