使用 MySQL CLI 命令从表中导出一行,例如:-
mysql -h mysql --user=root --password=root --database dms_home --xml -e "SELECT * FROM users WHERE account=4149;" >/var/www/scripts/output/1187515/1187515_users.sql
这将输出文件:-
<resultset statement="SELECT * FROM accounts WHERE accnum=1187515" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<row>
<field name="id">4149</field>
<field name="accnum">1187515</field>
<field name="applicationdate">0000-00-00</field>
<field name="introducer"></field>
<field name="jointacc">0</field>
<field name="consultancy">0</field>
<field name="storage">0</field>
<field name="digitalonly">0</field>
<field name="membership" xsi:nil="true" />
<field name="promocode"></field>
<field name="holdername" xsi:nil="true" />
<field name="testaccount">0</field>
</row>
</resultset>
现在,您可以看到 XML 行“membership”和“holdername”中有 2 个空值,如果我随后转到另一个 MySQL 服务器/数据库并重新导入此文件,使用显示警告开关,我会得到这个:-
mysql -h mysql -u root -p dms_licence --show-warnings -e "load xml local infile '/var/www/scripts/output/1187515/1187515_account.sql' into table dms_licence.accounts";
Warning (Code 1263): Column set to default value; NULL supplied to NOT NULL column 'id' at row 1
Warning (Code 1263): Column set to default value; NULL supplied to NOT NULL column 'accnum' at row 1
Warning (Code 1263): Column set to default value; NULL supplied to NOT NULL column 'applicationdate' at row 1
Warning (Code 1263): Column set to default value; NULL supplied to NOT NULL column 'introducer' at row 1
Warning (Code 1263): Column set to default value; NULL supplied to NOT NULL column 'jointacc' at row 1
Warning (Code 1263): Column set to default value; NULL supplied to NOT NULL column 'consultancy' at row 1
Warning (Code 1263): Column set to default value; NULL supplied to NOT NULL column 'storage' at row 1
Warning (Code 1263): Column set to default value; NULL supplied to NOT NULL column 'digitalonly' at row 1
Warning (Code 1263): Column set to default value; NULL supplied to NOT NULL column 'promocode' at row 1
Warning (Code 1263): Column set to default value; NULL supplied to NOT NULL column 'testaccount' at row 1
表模式是相同的,插入数据不会导致主键或唯一键出现任何问题。那么为什么它只插入一条空白记录呢?