MySQL Workbench 编辑表数据是只读的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10815029/
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
MySQL Workbench Edit Table Data is read only
提问by EscalinNancy
When trying Edit Table Data in MySQL Workbench 5.2.37, its in read only mode.
在 MySQL Workbench 5.2.37 中尝试编辑表数据时,它处于只读模式。
It is editable only if the table has a primary key.
仅当表具有主键时才可编辑。
Is there any fix to deal with table without primary key??
有没有办法处理没有主键的表??
Thanks
谢谢
As one of the suggestion I tried upgrading WB 5.2.40. But still this issue exists.. Could any one Help please..
作为建议之一,我尝试升级 WB 5.2.40。但是这个问题仍然存在..任何人都可以帮忙..
采纳答案by Thomas B
I'm assuming the table has a primary key. First try to run a unlock tables command to see if that fixes it.
我假设该表有一个主键。首先尝试运行解锁表命令以查看是否可以修复它。
If all else fails you can alter the table to create a new primary key column with auto-increment and that should hopefully fix it. Once you're done you should be able to remove the column without any issues.
如果所有其他方法都失败了,您可以更改表以创建一个具有自动增量的新主键列,这有望解决它。完成后,您应该能够毫无问题地移除该列。
As always you want to make a backup before altering tables around. :)
与往常一样,您希望在更改表之前进行备份。:)
Note: MySQL workbench cannot work without a primary key if that's your issue. However if you have a many to many table you can set both columns as primary keys which will let you edit the data.
注意:如果这是您的问题,MySQL 工作台无法在没有主键的情况下工作。但是,如果您有一个多对多的表,您可以将两列都设置为主键,这样您就可以编辑数据。
回答by Tarun Singhal
if the table does not have primary key or unique non-nullable defined, then MySql workbench could not able to edit the data.
如果表没有定义主键或唯一的不可为空,则 MySql 工作台无法编辑数据。
回答by Manitoba
If you set a default schema for your DB Connection then Select will run in readonly mode until you set explicitly your schema
如果您为数据库连接设置默认架构,则 Select 将以只读模式运行,直到您明确设置架构
USE mydb;
SELECT * FROM mytable
this will also run in edit mode:
这也将在编辑模式下运行:
SELECT * FROM mydb.mytable
(MySql 5.2.42 / MacOsX)
(MySql 5.2.42 / MacOsX)
I hope this helps.
我希望这有帮助。
回答by JerryGoyal
This is the Known limitationin MySQLWorkbench (you can't edit table w/o PK):
这是MySQLWorkbench 中的已知限制(您不能在没有 PK 的情况下编辑表):
To Edit the Table:
编辑表格:
Method 1:(method not working in somecases)
right-click on a table within the Object Browser and choose the Edit Table Data option from there.
方法 1:(该方法在某些情况下不起作用)
在对象浏览器中的表上单击鼠标右键,然后从那里选择“编辑表数据”选项。
Method 2:
I would rather suggest you to add Primary Key Instead:
方法 2:
我宁愿建议您添加主键:
ALTER TABLE `your_table_name` ADD PRIMARY KEY (`column_name`);
and you might want to remove the existing rows first:
并且您可能想先删除现有的行:
Truncate table your_table_name
回答by aesede
In MySQL Workbench you need an INDEX to edit, no need it to be PK (although adding a PK is a solution as well).
在 MySQL Workbench 中,您需要一个 INDEX 进行编辑,不需要它是 PK(尽管添加 PK 也是一个解决方案)。
You can make a regular INDEX or compound INDEX. That's all MySQL WB needs to fix the Read only thing (I have v. 6.2 with MariaDB v. 10.1.4):
您可以制作常规 INDEX 或复合 INDEX。这就是 MySQL WB 修复只读问题所需的全部内容(我有 6.2 版和 MariaDB 10.1.4 版):
Just right click table, select "Alter table..." then go to "Indexes" tab. In the left pane put a custom name for your index, and in the middle pane checkmark one (make sure the vale will be unique) or more fields (just make sure the combination is unique)
只需右键单击表,选择“更改表...”,然后转到“索引”选项卡。在左窗格中为您的索引输入一个自定义名称,并在中间窗格中勾选一个(确保该值是唯一的)或多个字段(只需确保组合是唯一的)
回答by Tarun Garg
Hovering over the icon "read only" in mysql workbench shows a tooltip that explains why it cannot be edited. In my case it said, only tables with primary keys or unique non-nullable columns can be edited.
将鼠标悬停在 mysql 工作台中的“只读”图标上会显示一个工具提示,解释为什么它不能被编辑。就我而言,它说,只能编辑具有主键或唯一不可为空列的表。
回答by Quad9x
I was getting the read-only problem even when I was selecting the primary key. I eventually figured out it was a casing problem. Apparently the PK column must be cased the same as defined in the table. using: workbench 6.3 on windows
即使在我选择主键时,我也遇到了只读问题。后来发现是外壳问题。显然,PK 列的大小写必须与表中定义的相同。使用:Windows 上的工作台 6.3
Read-Only
只读
SELECT leadid,firstname,lastname,datecreated FROM lead;
SELECT Leadid,firstname,lastname,datecreated FROM Lead;
Allowed edit
允许编辑
SELECT LeadID,firstname,lastname,datecreated FROM lead;
SELECT LeadID,firstname,lastname,datecreated FROM Lead;
回答by eggyal
According to this bug, the issue was fixed in Workbench 5.2.38 for some people and perhaps 5.2.39 for others—can you upgradeto the latest version (5.2.40)?
根据这个错误,该问题在 Workbench 5.2.38 中针对某些人已修复,而对于其他人可能在 5.2.39 中修复——您能升级到最新版本 (5.2.40) 吗?
Alternatively, it is possible to workaround with:
或者,可以通过以下方式解决:
SELECT *,'' FROM my_table
回答by Earth Engine
Guided by Manitoba's post, I found another solution. As a summary, the solutions are:
在 Manitoba 的帖子的指导下,我找到了另一个解决方案。总之,解决方案是:
With a USE command
USE mydb; SELECT * FROM mytable
With an explicit schema prefix:
SELECT * FROM mydb.mytable
GUI
On Object Browser "SCHEMAS" pane, all database icons are initially not highlighted if you have the same issue. So you can right click on the database icon you wanted to be the default, select "Set as default schema".
使用 USE 命令
USE mydb; SELECT * FROM mytable
使用显式架构前缀:
SELECT * FROM mydb.mytable
图形用户界面
在对象浏览器的“SCHEMAS”窗格中,如果您遇到相同的问题,最初不会突出显示所有数据库图标。因此,您可以右键单击要作为默认值的数据库图标,选择“设置为默认模式”。
回答by Degar007
1.)You have to make the primary key unique, then you should be able to edit.
1.) 你必须使主键唯一,然后你应该能够编辑。
right click on you table in the "blue" schemas ->ALTER TABLE, look for your primert key (PK), then just check the check-box, UN, the AI should already be checked. After that just apply and you should be able to edit the table data.
在“蓝色”模式中右键单击您的表 -> ALTER TABLE,查找您的入门密钥(PK),然后只需选中复选框 UN,AI 应该已经被选中。之后只需应用,您应该能够编辑表数据。
2.)You also need to include the primery key I your select statement
2.) 你还需要在你的选择语句中包含主键
Nr 1 is not really necessary, but a good practice.
Nr 1 并不是真正必要的,而是一个很好的做法。