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
how to import the database to mysql under linux?
提问by user1188320
The sql file named:bag.sql
in /var/www/html/web
(/var/www/html/web/bag.sql)
sql文件名为:bag.sql
in /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 pv
it is a piper viewer tool in linux.
这将显示导入的进度指示器。如果您从未使用过pv
它,它是 linux 中的 Piper 查看器工具。
回答by Ravikumar
Connect to mysql database server
$ mysql -uusername -ppassword
Check database exists are not
$ show databases;
If not create the same
mysql>create database mydb;
note: mydb is database name(Give your own).
Check again for the database follow step 2.
exit
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
Check for imported data.
连接到mysql数据库服务器
$ mysql -uusername -ppassword
检查数据库是否存在
$ 显示数据库;
如果没有创建相同的
mysql>创建数据库 mydb;
注意:mydb 是数据库名称(给你自己的)。
按照步骤 2 再次检查数据库。
出口
将数据导入 mydb(您自己的)数据库
$ mysql -uusername -ppassword mydb < bag.sql
注意:您的 bag.sql 位于您执行上述命令的当前目录中
检查导入的数据。
YES FOR LONG WAIT YOU NEED TO CHECK YOUR BAG.SQL FILE SIZE.
是的,等待很长时间,您需要检查您的 BAG.SQL 文件大小。
Symbol '$' is shell prompt
符号 '$' 是 shell 提示