MYSQL用source命令导入DB数据库文件失败

MYSQL用source命令导入DB数据库文件失败

create database exam;
use exam;
set names utf8;
source D:/exam.db;

img

img

文件路径改到D盘下面仍旧失败,初步认为是source命令的问题,是跟MySQL的版本有关吗?

source关键字仅受命令行客户端支持。你可以在mysql的命令行界面中使用。但在这里不行。这里你可以直接打开sql文件来执行。

  • 这个问题的回答你可以参考下: https://ask.csdn.net/questions/7692239
  • 你也可以参考下这篇文章:mysql使用source xxx.sql导入大文件.sql报错的解决方法
  • 除此之外, 这篇博客: Mysql导入Source数据库中的 方法1 source 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • [root@node002 ~]# mysql -uroot -p123456
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 3
    Server version: 5.1.73 Source distribution

    Copyright (c) 2000, 2013, 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> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | bigdata            |
    | bigshucang         |
    | hue                |
    | itcast_shop        |
    | mysql              |
    | rng_comment        |
    | test               |
    +--------------------+
    8 rows in set (0.00 sec)

    mysql> use 数据库名称
    Database changed
    mysql> source /opt/package/itcast_shop.sql
    Query OK, 0 rows affected (0.00 sec)

    Query OK, 0 rows affected (0.04 sec)

    Query OK, 0 rows affected (0.00 sec)

     

    你可以执行很多次都没有关系。

    可以执行数据库,可以执行单个表,都是可以的。

    mysql source命令执行先配置:

    找到my.cnf文件,
    
    find / -name my.cnf
    
    
    添加如下属性
    
    interactive_timeout = 120
    wait_timeout = 120
    max_allowed_packet = 100M
    mysql> source /opt/package/itcast_shop.sql;

     

    如果sql中是整个数据库,那么source之后,整个数据库都变了。如果只是整个表的数据,那么整个表的数据都变了。