1068 mysql 中定义的多个主键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28336162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
1068 multiple primary key defined in mysql
提问by mohankarunasiri
I export (with Update) my existing My SQL backup and import it to another PC via PHPAdmin but it gives below error message. I need to just replace existing database on backup PC. Is it possible to do this?
我导出(使用更新)我现有的我的 SQL 备份并通过 PHPAdmin 将其导入另一台 PC,但它给出了以下错误消息。我只需要替换备份 PC 上的现有数据库。是否有可能做到这一点?
"#1068 - Multiple primary key defined"
“#1068 - 定义了多个主键”
Thanks, Mohan K
谢谢,莫汉K
回答by Bitwise Creative
Yes, add drop table
option in your export, then on import, your table will be dropped and recreated. This will avoid pk conflicts.
是的,drop table
在导出中添加选项,然后在导入时,您的表将被删除并重新创建。这将避免pk冲突。
回答by spencer7593
To do a wholesale replacement of an existing database...
要对现有数据库进行批量替换...
One option is to drop the existing database and re-create it. But make sure you really want to do this, and that you are doing it on the MySQL instance you really want to do it on:
一种选择是删除现有数据库并重新创建它。但是请确保您真的想这样做,并且您是在您真正想在其上执行的 MySQL 实例上执行此操作:
DROP DATABASE mydb ;
CREATE DATABASE mydb ;
Note that this may have an effect on granted privileges, you may need to re-grant privileges on the new database. (In the CREATE DATABASE statement, include a specification for the default characterset and collation, if those differ from the setting of the instance variables.)
请注意,这可能会影响授予的权限,您可能需要重新授予新数据库的权限。(在 CREATE DATABASE 语句中,包括默认字符集和排序规则的规范,如果它们与实例变量的设置不同。)
SQLyog has a convenient "empty database" menu option, which drops all of the objects in the database without having to drop the database and re-create it. (This may have an effect on privileges granted to individual database objects.)
SQLyog 有一个方便的“空数据库”菜单选项,它可以删除数据库中的所有对象,而不必删除数据库并重新创建它。(这可能会影响授予单个数据库对象的权限。)
I'm not sure if phpmyadmin has an equivalent function. To roll your own, it's a matter of querying the information_schema
tables to identify all tables, views, procedures, etc.
我不确定 phpmyadmin 是否具有等效功能。要自己动手,只需查询information_schema
表以识别所有表、视图、过程等。
For example, to generate a list of the DROP TABLE
statements, you could run a query something like this:
例如,要生成DROP TABLE
语句列表,您可以运行如下查询:
SELECT CONCAT('DROP TABLE `',t.table_schema,'`.`',t.table_name,'` ;') AS stmt
FROM information_schema.tables t
WHERE t.table_schema = 'foo' ;
If the tables have foreign keys, you can either set the FOREIGN_KEY_CHECKS=0
for the session, or execute the drop statements in the appropriate order, etc. And repeat for the other object types: information_schema.routines
, etc.
如果表有外键,您可以FOREIGN_KEY_CHECKS=0
为会话设置,或以适当的顺序执行 drop 语句等。 并为其他对象类型重复:information_schema.routines
等。
回答by Alex
instead of drop database, empty it instead:
而不是删除数据库,而是清空它:
truncate tablename
(then add the pk again) When you do it this way don't have to recreate all tables and columns again.
(然后再次添加 pk)当您这样做时,不必再次重新创建所有表和列。