Home > Software engineering >  Excuse me, are on the server side, user data is stored in what is? Is a database?
Excuse me, are on the server side, user data is stored in what is? Is a database?

Time:10-21

I do a chat program, for example, the server will store all the user's information, such as name, gender, province, etc.,,,

These messages are generally, oneself do a structure array, the data stored in this structure, the server-side program exits, hard disk files saved to the server, the server starts up, the data read from disk again this structure in the array?

Or the user information stored in the database like mysql? Then use the mysql query language of database operations, add a record, query record?

Which is generally used?

CodePudding user response:

I now use the user data is stored in the structure of the array, name, age, gender, address and so on,,,

Server program exits, save the data to the hard disk, the server application starts, then loaded into the structure of data from hard disk file,

But that there is a drawback, that is, the structure of the C language data, each field is fixed, and I need a variable-length field, the variable-length field, the information of the users themselves, such as photos, some of the photos is very small, a few K, some pictures is very big, a few hundred K, if each user to the space of a few hundred K, could do a lot of waste,

And like mysql database, the most attractive thing is that can be stored longer fields, such as variable-length binary data, it is very useful to me, I'm prepared to give each user a personal weibo, weibo contents of each of the users themselves, is stored in their own variable-length field, while some users according to not tweeting, so, some needs a few M to 10 M of space, some don't need, word length field is not completed,

Excuse me, in this case, the mysql database is used to store user information a little better?

CodePudding user response:

Using a database to store user information and benefits, is the ability to change the length of the field, or add or remove a field, and does not affect the content,

And use the structure of the C language array to hold, it is impossible to do this, unless the new structure and old structure is put together, the data with the program reads from the old structure, deposit to the new structure, the word is not so convenient database operations,

I want to ask is: in general, the service side is saved user information in the database? Is it in your own design in the array?

CodePudding user response:

CodePudding user response:

Generally, text information database, save hard disk images, image path what written into the database,

Concurrent with no database, but it looks like you should not need,

CodePudding user response:

reference 4 floor homesos response:
normally, text information database, save hard disk images, image path what written into the database,

Concurrent with no database, but it seems that you should not need,


You mean: user id, nickname, password, sex, age, such as information, are stored in the database, text messages, for example, sent a message to b, and b is not online, this message will be temporarily in the server, there are records of b, such as b launched, the server is sent to him, these text messages, also is the existence of the database?

Image file, it is hard, then into the hard disk database file name, is it?

If the image file also exists in the form of binary database, what's wrong?

In addition, if each user has a weibo, like QQ space, each user to send their own content, look for a friend, such a weibo, there is a database? Or,,, with other file storage is better? This may be more big, if more users to send, may be as many as 10 M,

CodePudding user response:

There is a problem, that is, some structure, how is stored in the database, such as each user login, will have a socket_in structure, a total of 14 bytes, there are four bytes is the IP address, there are 2 bytes is the port number, otherwise 8 bytes are empty,

This structure, what is stored in the database? Use plastic volume storage is not good, use string storage is not good, use binary storage is not good,

CodePudding user response:

reference 5 floor screen12 reply:
Quote: refer to 4th floor homesos response:

Generally, text information database, save hard disk images, image path what written into the database,

Concurrent with no database, but it seems that you should not need,


You mean: user id, nickname, password, sex, age, such as information, are stored in the database, text messages, for example, sent a message to b, and b is not online, this message will be temporarily in the server, there are records of b, such as b launched, the server is sent to him, these text messages, also is the existence of the database?

Image file, it is hard, then into the hard disk database file name, is it?

If the image file also exists in the form of binary database, what's wrong?

In addition, if each user has a weibo, like QQ space, each user to send their own content, look for a friend, such a weibo, there is a database? Or,,, with other file storage is better? This may be more big, if more users to send, may be as many as 10 M,


1. The image file storage database a direct reference is not good, if put on a hard disk can directly read through HTTP, etc; Second, the database will be a big size, thus various efficiency will decrease, if use a large database is another matter,
2. In addition your question, involves the range is wide, this should use page caching,

CodePudding user response:

refer to 6th floor screen12 response:
there is a problem that is some structure, how is stored in the database, such as each user login, will have a socket_in structure, a total of 14 bytes, there are four bytes is the IP address, there are 2 bytes is the port number, otherwise 8 bytes are empty,

This structure, what is stored in the database? Use plastic volume storage is not good, use string storage is not good, use binary storage is not good,


I think this is kind of similar to the problem of language transformation, structure is your second language in the program, in the database, also have the language of the database performance, is the field, the structure of the field variables corresponding to the database,

CodePudding user response:

The second kind of database, data structure is just a way of storing data, is a kind of structure, and the database data is written on the hard drive, also is the physical storage

CodePudding user response:

Search "serialization and deserialization"
  • Related