Hướng dẫn how do i import a sql database into mysql using command line? - làm cách nào để nhập cơ sở dữ liệu sql vào mysql bằng dòng lệnh?

Use:

mysql -u root -p password -D database_name << import.sql

Sử dụng trợ giúp MySQL để biết chi tiết -

[~]$ mysql --help
mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --bind-address=name IP address to bind to.
  -D, --database=name Database to use.
  --delimiter=name    Delimiter to be used.
  --default-character-set=name Set the default character set.
  -f, --force         Continue even if we get an SQL error.
  -p, --password[=name] Password to use when connecting to server.
  -h, --host=name     Connect to host.
  -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
  --protocol=name     The protocol to use for connection (tcp, socket, pipe,
  -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
  -v, --verbose       Write more. (-v -v -v gives the table output format).
  -V, --version       Output version information and exit.
  -w, --wait          Wait and retry if connection is down.
0.

Tôi nghĩ rằng đây sẽ là những tùy chọn hữu ích trong bối cảnh của chúng tôi:

[~]$ mysql --help
mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --bind-address=name IP address to bind to.
  -D, --database=name Database to use.
  --delimiter=name    Delimiter to be used.
  --default-character-set=name Set the default character set.
  -f, --force         Continue even if we get an SQL error.
  -p, --password[=name] Password to use when connecting to server.
  -h, --host=name     Connect to host.
  -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
  --protocol=name     The protocol to use for connection (tcp, socket, pipe,
  -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
  -v, --verbose       Write more. (-v -v -v gives the table output format).
  -V, --version       Output version information and exit.
  -w, --wait          Wait and retry if connection is down.

Có gì thú vị, nếu chúng tôi đang nhập một cơ sở dữ liệu lớn và không có thanh tiến bộ. Sử dụng trình xem ống và xem truyền dữ liệu qua đường ống

Đối với Mac,

[~]$ mysql --help
mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --bind-address=name IP address to bind to.
  -D, --database=name Database to use.
  --delimiter=name    Delimiter to be used.
  --default-character-set=name Set the default character set.
  -f, --force         Continue even if we get an SQL error.
  -p, --password[=name] Password to use when connecting to server.
  -h, --host=name     Connect to host.
  -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
  --protocol=name     The protocol to use for connection (tcp, socket, pipe,
  -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
  -v, --verbose       Write more. (-v -v -v gives the table output format).
  -V, --version       Output version information and exit.
  -w, --wait          Wait and retry if connection is down.
1

Cho Debian/Ubuntu,

[~]$ mysql --help
mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --bind-address=name IP address to bind to.
  -D, --database=name Database to use.
  --delimiter=name    Delimiter to be used.
  --default-character-set=name Set the default character set.
  -f, --force         Continue even if we get an SQL error.
  -p, --password[=name] Password to use when connecting to server.
  -h, --host=name     Connect to host.
  -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
  --protocol=name     The protocol to use for connection (tcp, socket, pipe,
  -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
  -v, --verbose       Write more. (-v -v -v gives the table output format).
  -V, --version       Output version information and exit.
  -w, --wait          Wait and retry if connection is down.
2.

Đối với những người khác, hãy tham khảo PV - Trình xem ống

pv import.sql | mysql -u root -p password -D database_name

1.45GiB 1:50:07 [339.0KiB/s]   [=============>      ] 14% ETA 11:09:36
1.46GiB 1:50:14 [ 246KiB/s]     [=============>      ] 14% ETA 11:09:15
1.47GiB 1:53:00 [ 385KiB/s]     [=============>      ] 14% ETA 11:05:36

Tác giả đã chọn quỹ nguồn mở và miễn phí để nhận quyên góp như một phần của chương trình Write for quyên góp.

Giới thiệu

Nhập và xuất cơ sở dữ liệu là một nhiệm vụ phổ biến trong phát triển phần mềm. Bạn có thể sử dụng các kết xuất dữ liệu để sao lưu và khôi phục thông tin của bạn. Bạn cũng có thể sử dụng chúng để di chuyển dữ liệu đến một máy chủ mới hoặc môi trường phát triển.

Trong hướng dẫn này, bạn sẽ làm việc với các kết xuất cơ sở dữ liệu trong MySQL hoặc MARIADB (các lệnh có thể hoán đổi cho nhau). Cụ thể, bạn sẽ xuất một cơ sở dữ liệu và sau đó nhập cơ sở dữ liệu đó từ tệp kết xuất.

Điều kiện tiên quyết

Để nhập hoặc xuất cơ sở dữ liệu MySQL hoặc Mariadb, bạn sẽ cần:

  • Một máy ảo với người dùng sudo không root. Nếu bạn cần một máy chủ, hãy vào đây để tạo một giọt DigitalOcean chạy phân phối Linux yêu thích của bạn. Sau khi tạo, chọn phân phối của bạn từ danh sách này và làm theo hướng dẫn thiết lập máy chủ ban đầu của chúng tôi.
  • MySQL hoặc MariaDB đã cài đặt. Để cài đặt MySQL, hãy làm theo hướng dẫn của chúng tôi, cách cài đặt MySQL. Để cài đặt Mariadb, hãy làm theo hướng dẫn của chúng tôi, cách cài đặt Mariadb.
  • Một cơ sở dữ liệu mẫu được tạo trong máy chủ cơ sở dữ liệu của bạn. Để tạo một cái, hãy theo dõi, tạo ra một cơ sở dữ liệu mẫu, trong hướng dẫn của chúng tôi, một phần giới thiệu về các truy vấn trong MySQL.“Creating a Sample Database” in our tutorial, “An Introduction to Queries in MySQL”.

Lưu ý: Thay thế cho cài đặt thủ công, bạn có thể khám phá ứng dụng một cú nhấp chuột của DigitalOcean Marketplace. As an alternative to manual installation, you can explore the DigitalOcean Marketplace’s MySQL One-Click Application.

Bước 1 - Xuất cơ sở dữ liệu MySQL hoặc Mariadb

Cơ sở dữ liệu xuất khẩu tiện ích bảng điều khiển

[~]$ mysql --help
mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --bind-address=name IP address to bind to.
  -D, --database=name Database to use.
  --delimiter=name    Delimiter to be used.
  --default-character-set=name Set the default character set.
  -f, --force         Continue even if we get an SQL error.
  -p, --password[=name] Password to use when connecting to server.
  -h, --host=name     Connect to host.
  -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
  --protocol=name     The protocol to use for connection (tcp, socket, pipe,
  -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
  -v, --verbose       Write more. (-v -v -v gives the table output format).
  -V, --version       Output version information and exit.
  -w, --wait          Wait and retry if connection is down.
3 sang các tệp văn bản SQL. Điều này làm cho nó dễ dàng hơn để chuyển và di chuyển cơ sở dữ liệu. Bạn sẽ cần tên và thông tin đăng nhập cơ sở dữ liệu của bạn cho một tài khoản có các đặc quyền cho phép truy cập ít nhất chỉ đọc toàn bộ cơ sở dữ liệu.

Sử dụng

[~]$ mysql --help
mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --bind-address=name IP address to bind to.
  -D, --database=name Database to use.
  --delimiter=name    Delimiter to be used.
  --default-character-set=name Set the default character set.
  -f, --force         Continue even if we get an SQL error.
  -p, --password[=name] Password to use when connecting to server.
  -h, --host=name     Connect to host.
  -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
  --protocol=name     The protocol to use for connection (tcp, socket, pipe,
  -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
  -v, --verbose       Write more. (-v -v -v gives the table output format).
  -V, --version       Output version information and exit.
  -w, --wait          Wait and retry if connection is down.
3 để xuất cơ sở dữ liệu của bạn:

  1. mysqldump -u username -p database_name > data-dump.sql
  • [~]$ mysql --help
    mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
    Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
    Usage: mysql [OPTIONS] [database]
      -?, --help          Display this help and exit.
      -I, --help          Synonym for -?
      --bind-address=name IP address to bind to.
      -D, --database=name Database to use.
      --delimiter=name    Delimiter to be used.
      --default-character-set=name Set the default character set.
      -f, --force         Continue even if we get an SQL error.
      -p, --password[=name] Password to use when connecting to server.
      -h, --host=name     Connect to host.
      -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
      --protocol=name     The protocol to use for connection (tcp, socket, pipe,
      -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
      -v, --verbose       Write more. (-v -v -v gives the table output format).
      -V, --version       Output version information and exit.
      -w, --wait          Wait and retry if connection is down.
    
    5 là tên người dùng bạn có thể đăng nhập vào cơ sở dữ liệu với
  • [~]$ mysql --help
    mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
    Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
    Usage: mysql [OPTIONS] [database]
      -?, --help          Display this help and exit.
      -I, --help          Synonym for -?
      --bind-address=name IP address to bind to.
      -D, --database=name Database to use.
      --delimiter=name    Delimiter to be used.
      --default-character-set=name Set the default character set.
      -f, --force         Continue even if we get an SQL error.
      -p, --password[=name] Password to use when connecting to server.
      -h, --host=name     Connect to host.
      -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
      --protocol=name     The protocol to use for connection (tcp, socket, pipe,
      -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
      -v, --verbose       Write more. (-v -v -v gives the table output format).
      -V, --version       Output version information and exit.
      -w, --wait          Wait and retry if connection is down.
    
    6 là tên của cơ sở dữ liệu để xuất
  • [~]$ mysql --help
    mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
    Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
    Usage: mysql [OPTIONS] [database]
      -?, --help          Display this help and exit.
      -I, --help          Synonym for -?
      --bind-address=name IP address to bind to.
      -D, --database=name Database to use.
      --delimiter=name    Delimiter to be used.
      --default-character-set=name Set the default character set.
      -f, --force         Continue even if we get an SQL error.
      -p, --password[=name] Password to use when connecting to server.
      -h, --host=name     Connect to host.
      -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
      --protocol=name     The protocol to use for connection (tcp, socket, pipe,
      -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
      -v, --verbose       Write more. (-v -v -v gives the table output format).
      -V, --version       Output version information and exit.
      -w, --wait          Wait and retry if connection is down.
    
    7 là tệp trong thư mục hiện tại lưu trữ đầu ra.

Lệnh sẽ không tạo ra đầu ra trực quan, nhưng bạn có thể kiểm tra nội dung của

[~]$ mysql --help
mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --bind-address=name IP address to bind to.
  -D, --database=name Database to use.
  --delimiter=name    Delimiter to be used.
  --default-character-set=name Set the default character set.
  -f, --force         Continue even if we get an SQL error.
  -p, --password[=name] Password to use when connecting to server.
  -h, --host=name     Connect to host.
  -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
  --protocol=name     The protocol to use for connection (tcp, socket, pipe,
  -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
  -v, --verbose       Write more. (-v -v -v gives the table output format).
  -V, --version       Output version information and exit.
  -w, --wait          Wait and retry if connection is down.
7 để kiểm tra xem nó có phải là tệp kết xuất SQL hợp pháp không.

Chạy lệnh sau:

  1. head -n 5 data-dump.sql

Phần trên cùng của tệp sẽ trông tương tự như thế này, hiển thị kết xuất MySQL cho cơ sở dữ liệu có tên

[~]$ mysql --help
mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --bind-address=name IP address to bind to.
  -D, --database=name Database to use.
  --delimiter=name    Delimiter to be used.
  --default-character-set=name Set the default character set.
  -f, --force         Continue even if we get an SQL error.
  -p, --password[=name] Password to use when connecting to server.
  -h, --host=name     Connect to host.
  -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
  --protocol=name     The protocol to use for connection (tcp, socket, pipe,
  -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
  -v, --verbose       Write more. (-v -v -v gives the table output format).
  -V, --version       Output version information and exit.
  -w, --wait          Wait and retry if connection is down.
6.

SQL dump fragment

-- MySQL dump 10.13 Distrib 5.7.16, for Linux (x86_64) -- -- Host: localhost Database: database_name -- ------------------------------------------------------ -- Server version 5.7.16-0ubuntu0.16.04.1

Nếu bất kỳ lỗi nào xảy ra trong quá trình xuất,

[~]$ mysql --help
mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --bind-address=name IP address to bind to.
  -D, --database=name Database to use.
  --delimiter=name    Delimiter to be used.
  --default-character-set=name Set the default character set.
  -f, --force         Continue even if we get an SQL error.
  -p, --password[=name] Password to use when connecting to server.
  -h, --host=name     Connect to host.
  -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
  --protocol=name     The protocol to use for connection (tcp, socket, pipe,
  -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
  -v, --verbose       Write more. (-v -v -v gives the table output format).
  -V, --version       Output version information and exit.
  -w, --wait          Wait and retry if connection is down.
3 sẽ in chúng ra màn hình.

Bước 2 - Nhập cơ sở dữ liệu MySQL hoặc Mariadb

Để nhập một tệp kết xuất hiện có vào MySQL hoặc MariaDB, bạn sẽ phải tạo một cơ sở dữ liệu mới. Cơ sở dữ liệu này sẽ giữ dữ liệu đã nhập.

Trước tiên, hãy đăng nhập vào MySQL làm Root hoặc người dùng khác có đủ các đặc quyền để tạo cơ sở dữ liệu mới:root or another user with sufficient privileges to create new databases:

  1. mysql -u root -p

Lệnh này sẽ đưa bạn vào dấu nhắc MySQL Shell. Tiếp theo, tạo một cơ sở dữ liệu mới với lệnh sau. Trong ví dụ này, cơ sở dữ liệu mới được gọi là

pv import.sql | mysql -u root -p password -D database_name

1.45GiB 1:50:07 [339.0KiB/s]   [=============>      ] 14% ETA 11:09:36
1.46GiB 1:50:14 [ 246KiB/s]     [=============>      ] 14% ETA 11:09:15
1.47GiB 1:53:00 [ 385KiB/s]     [=============>      ] 14% ETA 11:05:36
1:

  1. CREATE DATABASE new_database;

Bạn sẽ thấy đầu ra này xác nhận việc tạo cơ sở dữ liệu.

Output

Query OK, 1 row affected (0.00 sec)

Sau đó thoát khỏi vỏ MySQL bằng cách nhấn

pv import.sql | mysql -u root -p password -D database_name

1.45GiB 1:50:07 [339.0KiB/s]   [=============>      ] 14% ETA 11:09:36
1.46GiB 1:50:14 [ 246KiB/s]     [=============>      ] 14% ETA 11:09:15
1.47GiB 1:53:00 [ 385KiB/s]     [=============>      ] 14% ETA 11:05:36
2. Từ dòng lệnh thông thường, bạn có thể nhập tệp kết xuất bằng lệnh sau:

  1. mysql -u username -p new_database < data-dump.sql
  • [~]$ mysql --help
    mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
    Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
    Usage: mysql [OPTIONS] [database]
      -?, --help          Display this help and exit.
      -I, --help          Synonym for -?
      --bind-address=name IP address to bind to.
      -D, --database=name Database to use.
      --delimiter=name    Delimiter to be used.
      --default-character-set=name Set the default character set.
      -f, --force         Continue even if we get an SQL error.
      -p, --password[=name] Password to use when connecting to server.
      -h, --host=name     Connect to host.
      -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
      --protocol=name     The protocol to use for connection (tcp, socket, pipe,
      -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
      -v, --verbose       Write more. (-v -v -v gives the table output format).
      -V, --version       Output version information and exit.
      -w, --wait          Wait and retry if connection is down.
    
    5 là tên người dùng bạn có thể đăng nhập vào cơ sở dữ liệu với
  • [~]$ mysql --help
    mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
    Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
    Usage: mysql [OPTIONS] [database]
      -?, --help          Display this help and exit.
      -I, --help          Synonym for -?
      --bind-address=name IP address to bind to.
      -D, --database=name Database to use.
      --delimiter=name    Delimiter to be used.
      --default-character-set=name Set the default character set.
      -f, --force         Continue even if we get an SQL error.
      -p, --password[=name] Password to use when connecting to server.
      -h, --host=name     Connect to host.
      -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
      --protocol=name     The protocol to use for connection (tcp, socket, pipe,
      -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
      -v, --verbose       Write more. (-v -v -v gives the table output format).
      -V, --version       Output version information and exit.
      -w, --wait          Wait and retry if connection is down.
    
    6 là tên của cơ sở dữ liệu để xuất
  • [~]$ mysql --help
    mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
    Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
    Usage: mysql [OPTIONS] [database]
      -?, --help          Display this help and exit.
      -I, --help          Synonym for -?
      --bind-address=name IP address to bind to.
      -D, --database=name Database to use.
      --delimiter=name    Delimiter to be used.
      --default-character-set=name Set the default character set.
      -f, --force         Continue even if we get an SQL error.
      -p, --password[=name] Password to use when connecting to server.
      -h, --host=name     Connect to host.
      -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
      --protocol=name     The protocol to use for connection (tcp, socket, pipe,
      -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
      -v, --verbose       Write more. (-v -v -v gives the table output format).
      -V, --version       Output version information and exit.
      -w, --wait          Wait and retry if connection is down.
    
    7 là tệp trong thư mục hiện tại lưu trữ đầu ra.

Lệnh sẽ không tạo ra đầu ra trực quan, nhưng bạn có thể kiểm tra nội dung của

[~]$ mysql --help
mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --bind-address=name IP address to bind to.
  -D, --database=name Database to use.
  --delimiter=name    Delimiter to be used.
  --default-character-set=name Set the default character set.
  -f, --force         Continue even if we get an SQL error.
  -p, --password[=name] Password to use when connecting to server.
  -h, --host=name     Connect to host.
  -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
  --protocol=name     The protocol to use for connection (tcp, socket, pipe,
  -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
  -v, --verbose       Write more. (-v -v -v gives the table output format).
  -V, --version       Output version information and exit.
  -w, --wait          Wait and retry if connection is down.
7 để kiểm tra xem nó có phải là tệp kết xuất SQL hợp pháp không.

Chạy lệnh sau:

Phần trên cùng của tệp sẽ trông tương tự như thế này, hiển thị kết xuất MySQL cho cơ sở dữ liệu có tên

[~]$ mysql --help
mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --bind-address=name IP address to bind to.
  -D, --database=name Database to use.
  --delimiter=name    Delimiter to be used.
  --default-character-set=name Set the default character set.
  -f, --force         Continue even if we get an SQL error.
  -p, --password[=name] Password to use when connecting to server.
  -h, --host=name     Connect to host.
  -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
  --protocol=name     The protocol to use for connection (tcp, socket, pipe,
  -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
  -v, --verbose       Write more. (-v -v -v gives the table output format).
  -V, --version       Output version information and exit.
  -w, --wait          Wait and retry if connection is down.
6.

Nếu bất kỳ lỗi nào xảy ra trong quá trình xuất,

[~]$ mysql --help
mysql  Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using  EditLine wrapper
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --bind-address=name IP address to bind to.
  -D, --database=name Database to use.
  --delimiter=name    Delimiter to be used.
  --default-character-set=name Set the default character set.
  -f, --force         Continue even if we get an SQL error.
  -p, --password[=name] Password to use when connecting to server.
  -h, --host=name     Connect to host.
  -P, --port=#        Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
  --protocol=name     The protocol to use for connection (tcp, socket, pipe,
  -s, --silent        Be more silent. Print results with a tab as separator, each row on new line.
  -v, --verbose       Write more. (-v -v -v gives the table output format).
  -V, --version       Output version information and exit.
  -w, --wait          Wait and retry if connection is down.
3 sẽ in chúng ra màn hình.

Bước 2 - Nhập cơ sở dữ liệu MySQL hoặc Mariadb

Tôi có thể nhập cơ sở dữ liệu SQL Server trong mysql không?

Quá trình này sẽ là xuất dữ liệu trực tiếp vào lưu trữ đối tượng OCI từ máy chủ MS SQL và sau đó nhập nó vào dịch vụ cơ sở dữ liệu MySQL bằng tiện ích MYSQL Shell () Utility đọc trực tiếp từ nhóm lưu trữ đối tượng.

Làm thế nào nhập cơ sở dữ liệu MySQL từ dòng lệnh windows?

Tạo nên cơ sở dữ liệu.Mở XAMPP và khởi động Cơ sở dữ liệu Apache và MySQL.....
Sao chép tệp SQL.Sao chép tệp SQL của bạn vào thư mục XAMPP/MySQL/bin/bin.....
Mở dấu nhắc lệnh.Mở dấu nhắc lệnh.....
Đầu ra.Mở phpmyadmin và chọn cơ sở dữ liệu để kiểm tra các bảng được nhập hay không ..
Conclusion..