What are the recommended values for MySQL database (id, user, password and email)?

2

I created a user table with the following values:

Tipo = 'MyISAM'

ID = 'int, PRIMARY, AI';   
Usuário = 'varchar, 16';   
Senha = 'varchar, 16';   
Email = 'varchar, 100';

Are these values recommended? Insurance?

    
asked by anonymous 24.05.2014 / 20:46

1 answer

12

It seems to be talking about configuring the structure of a table, not the values of a table. The correct concept helps to understand the problem.

You need a lot more information to be able to say for sure if it's a good database structure for your case. I will try to be objective based on my experience based on what you have informed.

The ID seems to be correct.

The others seem to be of type varchar appropriately. A type varchar in MySQL allows texts to be stored with a variable length between 0 and 65535 bytes (which may not mean 65535 characters if using UTF8, for example). Essentially only the space actually needed for the individual text is consumed in the table. So normally for the sake of space it does not make much sense to set a boundary for the column. In fact it even has a limit that is 65535. Of course in practice you can not have a column of this size because this is also the limit for the size of the line.

Why put a lower value? Maybe because you're sure that it will never be or never can be exceeded.

But if you are sure that text is fixed in size, it may be best to use char . If you want to set a limit that can not be exceeded, you are using the database structure to do validation. It works, but it is not always the right one.

If you are going to use this type of validation make sure your application knows how to handle an error generated by having violated this limit.

Of course this validation can be done in the application as well and it is probably a good idea not to try to record something that is known to be invalid.

The sizes for Usuário and Senha seem small, but you can respond better than I do. Where do these data come from? Do you have control of how this is registered? Is there no way to need bigger size? If you do not have absolute control over the size, it is best to leave a larger size, perhaps 255.

Will the password be recorded as? Pure and simple? You know the implications of this? You will not at least use the password() function to generate a hash of the password strong> ? If you will use this, 41 bytes will be required. But will not you use any other method? It may be too short. Read the text that Bacco linkou in the comment. If you know the size of the password is fixed ( hash ), the column does not have to be varchar , but there is also no harm in being. Some people tend to think that one type has more performance than another, but that may not be true.

E-mail is usually a few tens of characters, but it is possible to have 254 characters . I would easily put the size 254 for this column, nor would I think of smaller size. Information can be obtained from the SMTP RFC . 100 should not cause problems (until it causes), in fact many providers do not even allow addresses that exceed this limit, but if you want a robust solution that solves the problem, leave 254. Putting 100 is opinion.

If you need some more detailed information than this, it would be good to edit and provide more detail in the question.

    
24.05.2014 / 22:07