简体   繁体   English

将mysql转储文本文件恢复到数据库

[英]Restoring mysql dump text file to database

I am working with analysing big data using opencl.我正在使用 opencl 分析大数据。 I got the data in mysql dump text file (dump.txt).我在 mysql 转储文本文件 (dump.txt) 中得到了数据。 I want to restore the data into mysql database.我想将数据恢复到mysql数据库中。 Then I can connect to the database and do the other stuff related to parallel programming to analysis big data.然后我可以连接到数据库并做其他与并行编程相关的工作来分析大数据。

I went through some tutorials and questions related this.我经历了一些与此相关的教程和问题。 I found a related question here.我在这里找到了一个相关的问题。 link here . 链接在这里 But there they mentioned the way to restore .sql dump file.但是他们提到了恢复 .sql 转储文件的方法。 what can we do for dump text files?我们可以为转储文本文件做些什么?

Abstract part of my dump text file is here我的转储文本文件的抽象部分在这里

"94723605719","435035","2013-06-01 23:51:36","2013-06-01","2013","6","1","7","22 ","23","51","36","1","202","-1002409728","1005823215","50000.000",\\N,"1613003749 10","50026.000","226","0","0","94723605719","34399725","0","0","0",\\N "94722616878","435014","2013-06-01 23:51:52","2013-06-01","2013","6","1","7","22 ","23","51","52","1","202","-1002099361","1005511506","50000.000",\\N,"1613002394 31","50127.000","157","0","0","94722616878","34438596","0","0","0",\\N "94726556777","435022","2013-06-01 23:51:52","2013-06-01","2013","6","1","7","22 ","23","51","52","1","202","-1002496570","1005910182","50000.000",\\N,"1614002967 42","61046.000","226","0","0","94726556777","34399744","0","0","0",\\N "94723605719"、"435035"、"2013-06-01 23:51:36"、"2013-06-01"、"2013"、"6"、"1"、"7"、"22"、" 23","51","36","1","202","-1002409728","1005823215","50000.000",\\N,"1613003749 10","50026.060","0228" ","0","94723605719","34399725","0","0","0",\\N "94722616878","435014","2013-06-01 23:51:52"," 2013-06-01","2013","6","1","7","22","23","51","52","1","202","-1002099361 ","1005511506","50000.000",\\N,"1613002394 31","50127.000","157","0","0","94722616878","344380,"0"," "0",\\N "94726556777","435022","2013-06-01 23:51:52","2013-06-01","2013","6","1","7" ,"22","23","51","52","1","202","-1002496570","1005910182","50000.000",\\N,"1614002967 42","610"46. "226","0","0","94726556777","34399744","0","0","0",\\N

Any help is appreciated.任何帮助表示赞赏。 Thanks in advance.提前致谢。

If you have 'real' dump, then you can use:如果您有“真正的”转储,则可以使用:

mysql -u root -p -h local host < your_dump.sql

That said, your example listed in the question seems to hint that you just have the values in a CSV file, in which case you need to first create the table and then load the data into it:也就是说,您在问题中列出的示例似乎暗示您只有 CSV 文件中的值,在这种情况下,您需要先创建表,然后将数据加载到其中:

LOAD DATA INFILE 'your_file.txt' 
 INTO TABLE your_table 
 FIELDS TERMINATED BY ',' 
 OPTIONALLY ENCLOSED BY '"';

See MySQL manual for LOAD DATA INFILE for more details.有关LOAD DATA INFILE的更多详细信息,请参阅 MySQL 手册。

I'm used to migrate MySql databases and the best way for me is like this:我习惯迁移MySql数据库,对我来说最好的方法是这样的:

Export Database(backup):导出数据库(备份):

mysqldump -u root -p [database_name] >  [dump_filename].sql

Import Database:导入数据库:

mysql -u root -p [database_name] < [dump_filename].sql

If the database you want to restore doesn't already exist, you need to create it first.如果要还原的数据库不存在,则需要先创建它。

On the command-line, if you're in the same directory that contains the dumped file, use these commands (with appropriate substitutions):在命令行上,如果您位于包含转储文件的同一目录中,请使用以下命令(使用适当的替换):

C:\> mysql -u root -p

mysql> create database mydb;
mysql> use mydb;
mysql> source db_backup.dump;

https://dev.mysql.com/doc/mysql-backup-excerpt/5.6/en/using-mysqldump.html https://dev.mysql.com/doc/mysql-backup-excerpt/5.6/en/using-mysqldump.html

http://meta.wikimedia.org/wiki/Database_dump_and_restore_examples http://meta.wikimedia.org/wiki/Database_dump_and_restore_examples

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM