您需要编写一些自定义代码来将其所有数据导入到MySQL中。愚蠢的答案堆栈溢出有史以来,对吧?
因此,他们提供了一组平面文件,每个平面文件在自述文件中都有描述。
README
allbut.pl
mku.sh
u.data
u.genre
u.info
u.item
u.occupation
u.user
u1.base
u1.test
u2.base
u2.test
u3.base
u3.test
u4.base
u4.test
u5.base
u5.test
ua.base
ua.test
ub.base
ub.test
一言以蔽之:
- 请在MySQL自己的数据库和表。
- 以编程方式打开文件并将每行解析为SQL。
- 将SQL导入到MySQL中。
- ???
- 利润!
是的,我知道我还没有真的告诉过你什么,让我们做一个,你可以希望做其他人。
我会做u.genre,因为我很懒,很容易。
制作一个新表格,我会假设你知道如何制作表格等。
u.genre有两件事:流派和身份证。
unknown|0
Action|1
...etc...
所以你的表应该有两个字段。
您将使用两种数据类型:https://dev.mysql.com/doc/refman/5.7/en/data-types.html
ID - 无符号的TINYINT
TINYINT无符号为0到255
流派 - VARCHAR(20)
VARCHAR 20达20个字符,最长的是“纪录片”,这样如果他们添加一个新的,就会给你一点额外的空间。
打开文件得到的内容:https://secure.php.net/manual/en/function.file-get-contents.php
$filecontents = file_get_contents("u.genre");
现在,让我们通过线分割的文件:https://secure.php.net/manual/en/function.explode.php
$genres = explode("\n", $filecontents);
现在,我们将通过$流派循环使用的foreach和再次爆炸:https://secure.php.net/manual/en/control-structures.foreach.php
foreach ($genres as &$row) {
list($genre,$id) = explode("|",$row);
# more here later
}
现在让我们来输出SQL,如果其中任何一个字段为空,则跳过。
if ($genre!="" && $id!=="") {
print "INSERT INTO genre (genre,id) VALUES ($genre,$id);\n";
}
把它放在一起......
<?php
$filecontents = file_get_contents("u.genre");
$genres = explode("\n", $filecontents);
foreach ($genres as &$row) {
list($genre,$id) = explode("|",$row);
if ($genre!="" && $id!=="") {
$sql = "INSERT INTO genre (genre,id) VALUES ($genre,$id);\n";
print $sql;
# Insert each into your DB here.
}
}
?>
保存它,并从命令行运行它或把它在浏览器中没有很好的理由。
这里有太多的资源显示如何将数据插入到MySQL中,所以我会放在这里。每个人的数据库设置都有所不同,因此为我的特定设置编写它不会对您有所帮助。