注:是装XML文件的内容,不是将XML作为二进制存储。
例如:有个表table1,存在3个字段a,b,c。现在将这3个字段的数值存到XML文件中,装载时直接入库。请问,怎么让Mysql读取这个XML格式文件。load data infile 的那些个命令能用吗
例如:有个表table1,存在3个字段a,b,c。现在将这3个字段的数值存到XML文件中,装载时直接入库。请问,怎么让Mysql读取这个XML格式文件。load data infile 的那些个命令能用吗
解决方案 »
- 既要用LIKE 有要用等号 而且是或得关系
- 大家帮忙看下这个sql语句的问题,困扰我一天了
- mysql 修改查询数据的问题
- mysql 安装好后有 mysql 、test、information_schema库
- 在數據庫中建了一個用戶,怎樣操作才能使得它只可以對裡面其中一個數據庫只有select 權限呢?
- 帮忙!!ERROR 1064 (42000): You have an error in your SQL syntax;
- Group by组合后记录的显示顺序问题
- 第一次用mysql求救,txt导入文本里有中文会自动停止,已设置成utf8也无用
- innodb_buffer_pool_size的大小设置
- 高手帮忙看下怎么解决,无奈sql学的太烂,试了一天没结果。
- mysql存储过程的问题
- 十万火急!!!求助:windows下Mysql触发器的问题
10.42 Exporting Query Results as XML
10.43 Importing XML into MySQL以下附上书中的脚本:xml_to_mysql.pl#! /usr/bin/perl -w
# xml_to_mysql.pl - read XML file into MySQLuse strict;
use DBI;
use XML::XPath;# ... process command-line options (not shown) ...# ... connect to database (not shown) ...# Open file for reading
my $xp = XML::XPath->new (filename => $file_name);
my $row_list = $xp->find ("//row"); # find set of <row> elements
print "Number of records: " . $row_list->size ( ) . "\n";
foreach my $row ($row_list->get_nodelist ( )) # loop through rows
{
my @name; # array for column names
my @val; # array for column values
my $col_list = $row->find ("*"); # children (columns) of row
foreach my $col ($col_list->get_nodelist ( )) # loop through columns
{
# save column name and value
push (@name, $col->getName ( ));
push (@val, $col->string_value ( ));
}
# construct INSERT statement, then execute it
my $stmt = "INSERT INTO $tbl_name ("
. join (",", @name)
. ") VALUES ("
. join (",", ("?") x scalar (@val))
. ")";
$dbh->do ($stmt, undef, @val);
}$dbh->disconnect ();