Mysql phpMyAdmin 几个问题:
我对 mysql phpMyadmin 环境很陌生,我想要一些区域 1. 我需要一个最多 500 个字符左右的文本字段。 那必须是“TEXT”字段吗?是否需要应用程序对长度负责?
索引。据我所知,当我将一个字段表示为“索引”时,这意味着该字段将有一个指针表,并且在每个 WHERE 包含命令上,搜索将通过该字段进行优化(log n 复杂度)。但是,如果我将某个字段表示为事后索引,会发生什么情况?在它有一些行之后说?我可以发出“遍历所有表并索引该字段”之类的命令吗?
当我将字段标记为索引时,我有时会在 phpMyAdmin 中将它们获取为具有键名
用于通过当我编写 php 时,我是否需要付出额外的努力来使用在“结构”视图中写下的键名来使用表作为索引,或者该键名是否在幕后使用并且我应该无论如何都不关心它?
有时我会得到同时引用两个或多个字段的键名。这些字段显示一个在另一个之上。我不知道这是怎么发生的,但我需要它们只索引一个字段。到底是怎么回事 ?
我在数据库中使用 UTF-8 值。当我创建它时,我想我将其标记为utf8_unicode_ci,并且某些字段标记为utf8_general_ci,这有关系吗?我可以返回并将整个数据库定义更改为 utf8_general_ci 吗?
我认为那是相当多的, 我先谢谢你了! 特德
I am quite new to the mysql phpMyadmin environment, and I would like to have some area
1. I need a field of text that should be up to around 500 characters.
Does that have to be "TEXT" field? does it take the application to be responsible for the length ?
indexes. I understand that when I signify a field as "indexed", that means that field would have a pointer table and upon each a WHERE inclusive command, the search would be optimized by that field (log n complexity). But what happens if I signify a field as indexed after the fact ? say after it has some rows in it ? can I issue a command like "walk through all that table and index that field" ?
When I mark fields as indexed, I sometimes get them in phpMyAdmin as having the keyname
for accessing the table by the indexed field when I write php, does it take an extra effort on my side to use that keyname that is written down there at the "structure" view to use the table as indexed, or does that keyname is being used behind the scenes and I should not care about it whatsoever ?
I sometimes get the keynames referencing two or more fields altogether. The fields show one on top of the other. I don't know how it happened, but I need them to index only one field. What is going on ?
I use UTF-8 values in my db. When I created it, I think I marked it as utf8_unicode_ci, and some fields are marked as utf8_general_ci, does it matter ? Can I go back and change the whole DB definition to be utf8_general_ci ?
I think that was quite a bit,
I thank you in advance!
Ted
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,请注意,这本身并不是关于 phpmyadmin 的事情,而是更多关于 mysql/数据库的事情。
1)
索引意味着您创建存在值的列表(大多数情况下是树)。这样您就可以轻松找到具有该/那些值的行。在插入值之后可以像之前一样轻松地创建此树。请注意,这意味着所有“添加到索引”命令都放在一起,因此您不想在包含大量条目的“实时”表上执行此操作。但您可以随时添加索引。只需添加索引,就会为空表或“已用”表创建索引。
2)
我不知道你说的是什么意思。索引有一个名称,它是什么并不重要。 (主)键是一个索引,但并非所有索引都是键。
3)
你不需要“强制”mysql使用密钥,优化器最清楚如何以及何时使用密钥。如果你的密钥正确,它们就会被使用,如果它们不正确,它们就不能使用,所以你不能强制它:换句话说:不要考虑它:)
4)
如果你标记,PHPMYADMIN 会生成一个复合密钥2个字段同时作为键。这很烦人并且可能是错误的。如果您一次搜索 2 件事,则可以使用组合键,但如果您搜索 1 件事,则不能。只需将它们一次标记为一个关键项,或者手动使用正确的 SQL 命令即可。
5)
你可以改变任何你喜欢的东西,但我不知道你的价值观会发生什么。最好手动检查一下:)
First, be aware that this not per se something about phpmyadmin, but more about mysql / databases.
1)
An index means that you make a list (most of the time a tree) of the values that are present. This way you can easily find the row with that/those values. This tree can be just as easily made after you insert values then before. Mind you, this means that all the "add to index" commands are put together, so not something you want to do on a "live" table with loads of entries. But you can add an index whenever you want it. Just add the index and the index will be made, either for an empty table or for a 'used' one.
2)
I don't know what you mean by this. Indexes have a name, it doesn't really matter what it is. A (primary) key is an index, but not all indexes are keys.
3)
You don't need to 'force' mysql to use a key, the optimizer knows best how and when to use keys. If your keys are correct they are used, if they are not correct they can't be used so you can't force it: in other words: don't think about it :)
4)
PHPMYADMIN makes a composite keys if you mark 2 fields as key at the same time. THis is annoying and can be wrong. If you search for 2 things at once, you can use the composite key, but if you search for the one thing, you can't. Just mark them as a key one at a time, or use the correct SQL command manually.
5)
you can change whatever you like, but I don't know what will happen with your values. Better check manually :)
如果您需要一个字段包含 500 个字符,则可以使用 VARCHAR 来实现。只需将其长度设置为 500。
您不需要逐个字段建立索引,而是对整个列建立索引。所以表中是否有数据并不重要。所有行都将被索引。
不是问题
索引将尽可能使用。您只需担心使用在查询的 WHERE 部分中索引的相同列即可。 在此处阅读
您可以添加索引中包含任意数量的列。例如,如果您将“foo”、“bar”和“ming”列添加到索引中,您的数据库将针对按顺序在 WHERE 子句中使用这些列的搜索进行速度优化。同样,上面的链接解释了这一切。
我不知道。我 100% 确定,如果您在数据库中仅使用 UTF-8 值,那没关系。不过,您可以稍后更改此设置,如 Stackoverflow 问题中所述:如何将整个 MySQL 数据库字符集和排序规则转换为 UTF-8?< /a>
不过,我建议您放弃 HeidiSQL 的 PHPMyAdmin。 HeidiSQL 是一个 Windows 客户端,用于管理所有 MySQL 服务器。它有很多很酷的功能,比如将表或数据库直接从一台 MySQL 服务器复制到另一台。尝试一下(免费)
If you need a field to contain 500 characters, you can do that with VARCHAR. Just set its length to 500.
You don't index field by field, you index a whole column. So it doesn't matter if the table has data in it. All the rows will be indexed.
Not a question
The indexes will be used whenever they can. You only need to worry about using the same columns that you have indexed in the WHERE section of your query. Read about it here
You can add as many columns as you wish in an index. For example, if you add columns "foo", "bar" and "ming" to an index, your database will be speed optimized for searches using those columns in the WHERE clause, in that order. Again, the link above explains it all.
I don't know. I'm 100% sure that if you use only UTF-8 values in the database, it won't matter. You can change this later though, as explained in this Stackoverflow question: How to convert an entire MySQL database characterset and collation to UTF-8?
I would recommend you scrap PHPMyAdmin for HeidiSQL though. HeidiSQL is a windows client that manages all your MySQL servers. It has lots of cool functions, like copying a table or database directly from one MySQL server to another. Try it out (it's free)