Import an SQL file with the MySQL Command Line Client

更新时间:
复制 MD 格式

This topic describes how to import a local sql file into a Web Hosting database using the MySQL Command Line Client.

Prerequisites

MySQL is installed on your local machine. You can download MySQL from the official MySQL website.

Procedure

  1. Obtain database information.
    1. Log on to the Web Hosting console.
    2. Find your target Web Hosting instance and click Manage in the Actions column.
    3. In the left-side navigation pane, click Database Information.
    4. On the Database Information page, note the database endpoint, database account, and database name.
      Note If you forget the database password, you can reset it. For more information, see Reset the database password for Web Hosting.
      数据库
  2. Open a Command Prompt window.

  3. Run the following command to import the local sql file into the Web Hosting database.

  4. mysql -h <database endpoint> -u <database account> -p --default-character-set=utf8 <database name> < path/to/your/local/file.sql

    For example, to import the backup file bdmxxxxxx_db.sql from the D: drive to a Web Hosting database:

    1. Run the preceding command.

    2. Enter the password when prompted.

    Important

    If you see the error message 'mysql' is not recognized as an internal or external command, operable program or batch file.', it means the path to the MySQL\bin directory is likely missing from your Path environment variable.

    You can resolve this issue in one of the following ways:

    • Add the path to the MySQL\bin directory to your Path environment variable. You may need to restart your computer for the change to take effect. Then, you can run the mysql command from any directory.

    • Use the cd command to navigate to the MySQL\bin directory. Then, run the mysql command from this directory.

Results

Running the command imports the data from the local sql file into the Web Hosting database.