gpt4 book ai didi

mysql - 如何使用 MySQL 转储 'update table, if table exists'?

转载 作者:行者123 更新时间:2023-11-29 01:45:15 25 4
gpt4 key购买 nike

我目前正在使用 mysqldump 转储 MySQL 表。

转储当前正在生成:

DROP TABLE IF EXISTS `versions`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `versions` (
`major` int(11) NOT NULL DEFAULT '0',
`minor` int(11) NOT NULL DEFAULT '0',
`revision` int(11) NOT NULL DEFAULT '0',
`build` int(11) NOT NULL DEFAULT '0',
`date_installed` datetime NOT NULL,
`current` tinyint(4) NOT NULL DEFAULT '0',
`product_type` varchar(30) DEFAULT NULL,
`product` varchar(30) DEFAULT NULL,
`product_class_name` varchar(80) DEFAULT NULL,
`lazy_load` tinyint(4) NOT NULL DEFAULT '0',
`sitewide` tinyint(4) NOT NULL DEFAULT '0',
UNIQUE KEY `versions_pkey` (`product`,`major`,`minor`,`revision`,`build`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

我想转储说的是,

IF TABLE EXISTS, UPDATE IT TO MATCH THIS STRUCTURE (
`major` int(11) NOT NULL DEFAULT '0',
`minor` int(11) NOT NULL DEFAULT '0',
`revision` int(11) NOT NULL DEFAULT '0',
`build` int(11) NOT NULL DEFAULT '0',
`date_installed` datetime NOT NULL,
`current` tinyint(4) NOT NULL DEFAULT '0',
`product_type` varchar(30) DEFAULT NULL,
`product` varchar(30) DEFAULT NULL,
`product_class_name` varchar(80) DEFAULT NULL,
`lazy_load` tinyint(4) NOT NULL DEFAULT '0',
`sitewide` tinyint(4) NOT NULL DEFAULT '0',
UNIQUE KEY `versions_pkey` (`product`,`major`,`minor`,`revision`,`build`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

这是否可以通过 MySQL 转储(或任何其他与 MySQL 相关的工具)实现?

谢谢

最佳答案

您可能需要提前转储架构并将 CREATE TABLE 转换为 CREATE TABLE IF NOT EXISTS

mysqldump -u... -p... --no-data --skip-add-drop-table ... --all-databases | sed 's/CREATE TABLE/CREATE TABLE IF NOT EXISTS/g' > MYSQLSchema.sql

这将绕过添加 DROP TABLE IF EXISTS versions; 命令并将 CREATE TABLE 转换为 CREATE TABLE IF NOT EXISTS

试一试!!!

关于mysql - 如何使用 MySQL 转储 'update table, if table exists'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8603182/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com