linux下如何将数据库导入mysql?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9875330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:24:53  来源:igfitidea点击:

how to import the database to mysql under linux?

mysqllinuxcentos

提问by user1188320

The sql file named:bag.sqlin /var/www/html/web(/var/www/html/web/bag.sql)

sql文件名为:bag.sqlin /var/www/html/web(/var/www/html/web/bag.sql)

the current directory is [localhost web]i used mysql -uusername -p databasename > bag.sql

[localhost web]我使用的当前目录mysql -uusername -p databasename > bag.sql

then let me input the password. i wait for long time, it doesn't show ok. why? how to import the database to mysql under centos.

然后让我输入密码。我等了很长时间,它没有显示正常。为什么?centos下如何将数据库导入mysql。

采纳答案by Kaustubh Karkare

if you have already created database then use below steps to import data from .sql file

如果您已经创建了数据库,则使用以下步骤从 .sql 文件中导入数据

tell which database to use:

告诉使用哪个数据库:

 use databasename;

Now give the source file path

现在给出源文件路径

 source /var/www/html/web/bag.sql;

回答by Joni

You need mysql -uusername -p databasename < bag.sql.

你需要mysql -uusername -p databasename < bag.sql.

<     Means "get the program's input from this file"
>     Means "write the program's output to this file"

回答by Kaustubh Karkare

you're using the wrong redirection operator. >is used for sending the output toa file, not taking input froma file. Use <.

您使用了错误的重定向运算符。>用于将输出发送文件,而不是文件中获取输入。使用<.

回答by danielrsmith

Let me offer up another alternative using pv

让我提供另一种选择,使用 pv

pv /path/to/file.sql | mysql -uUSERNAME -pPASSWORD -D DATABASE_NAME

pv /path/to/file.sql | mysql -uUSERNAME -pPASSWORD -D DATABASE_NAME

This will show you a progress indicator for the import. If you have never used pvit is a piper viewer tool in linux.

这将显示导入的进度指示器。如果您从未使用过pv它,它是 linux 中的 Piper 查看器工具。

回答by Ravikumar

  1. Connect to mysql database server

    $ mysql -uusername -ppassword

  2. Check database exists are not

    $ show databases;

  3. If not create the same

    mysql>create database mydb;

    note: mydb is database name(Give your own).

  4. Check again for the database follow step 2.

  5. exit

  6. Import data to mydb(your own) database

    $ mysql -uusername -ppassword mydb < bag.sql

    note: your bag.sql is in the current directory from where you are executing the above command

  7. Check for imported data.

  1. 连接到mysql数据库服务器

    $ mysql -uusername -ppassword

  2. 检查数据库是否存在

    $ 显示数据库;

  3. 如果没有创建相同的

    mysql>创建数据库 mydb;

    注意:mydb 是数据库名称(给你自己的)。

  4. 按照步骤 2 再次检查数据库。

  5. 出口

  6. 将数据导入 mydb(您自己的)数据库

    $ mysql -uusername -ppassword mydb < bag.sql

    注意:您的 bag.sql 位于您执行上述命令的当前目录中

  7. 检查导入的数据。

YES FOR LONG WAIT YOU NEED TO CHECK YOUR BAG.SQL FILE SIZE.

是的,等待很长时间,您需要检查您的 BAG.SQL 文件大小。

Symbol '$' is shell prompt

符号 '$' 是 shell 提示

回答by parisssss

mysql -u username -p -h localhost DATA-BASE-NAME < data.sql

mysql -u 用户名 -p -h localhost DATA-BASE-NAME < data.sql

source

来源