Imitate Mo Mo eight avatar's database, how should build the table to be suitable?

Source: Internet
Author: User
I think everyone has read my previous question. is The Spit Groove entrepreneurship is very difficult. My ability is not enough, basically my experience is segmentfault above one of the questions obtained. Here, I would like to thank those who have helped me, no matter how naïve the question will be enthusiastic to answer you.
Of course, I have a new problem. is the Mo Mo's eight picture, Mo Mo in backstage is how to save (is how to build the table)
My technical opinion is very superficial, but I estimate that Mo Mo's personal data is not used in MySQL to save, but with MongoDB.

Of course, the picture file must exist in the file system, the path must be saved in the table!!
and to use MySQL to save the words:

CREATE TABLE  travel_user_avatar(  userId     INT UNSIGNED  PRIMARY KEY  NOT NULL  COMMENT ' 用户的唯一id',  avatar0  VARCHAR(255) DEFAULT '',  avatar1  VARCHAR(255)DEFAULT '',  avatar2  VARCHAR(255)DEFAULT '',  avatar3  VARCHAR(255)DEFAULT '',   CONSTRAINT `useravatar` FOREIGN KEY (`userId`) REFERENCES `travel_user_meta` (`userId`) ON DELETE CASCADE ON UPDATE CASCADE);

If you use MySQL, do you want to build the table?
Recently did a period of projects, or found a lot of relational database deficiencies. For example this piece of personal data, with a non-relational database is much better than the relational database Ah!!

Reply content:

I think everyone has read my previous question. is The Spit Groove entrepreneurship is very difficult. My ability is not enough, basically my experience is segmentfault above one of the questions obtained. Here, I would like to thank those who have helped me, no matter how naïve the question will be enthusiastic to answer you.
Of course, I have a new problem. is the Mo Mo's eight picture, Mo Mo in backstage is how to save (is how to build the table)
My technical opinion is very superficial, but I estimate that Mo Mo's personal data is not used in MySQL to save, but with MongoDB.

Of course, the picture file must exist in the file system, the path must be saved in the table!!
and to use MySQL to save the words:

CREATE TABLE  travel_user_avatar(  userId     INT UNSIGNED  PRIMARY KEY  NOT NULL  COMMENT ' 用户的唯一id',  avatar0  VARCHAR(255) DEFAULT '',  avatar1  VARCHAR(255)DEFAULT '',  avatar2  VARCHAR(255)DEFAULT '',  avatar3  VARCHAR(255)DEFAULT '',   CONSTRAINT `useravatar` FOREIGN KEY (`userId`) REFERENCES `travel_user_meta` (`userId`) ON DELETE CASCADE ON UPDATE CASCADE);

If you use MySQL, do you want to build the table?
Recently did a period of projects, or found a lot of relational database deficiencies. For example this piece of personal data, with a non-relational database is much better than the relational database Ah!!

I think the address of your avatar does not need to be stored, such as all the user's avatar is under a folder, using the UID plus another logo to distinguish the file name is good, each time automatically stitching the URL. For example/avatar_1000 (UID) _a1 (size mark). jpg,/avatar_1000 (UID) _a2.jpg just fine ~

This situation is not necessarily to MongoDB's bar ... A direct User_avatar table out, id,user_id and Avatar fields are good. Individuals are inclined to use MySQL heavily. Redis is used only in certain places, such as tags and relationships. MongoDB is almost not used.

(I Caishuxueqian, laughed at)

First of all, the possible way:

    1. Can follow the way you give
    2. You can split the column into line userId Avatar Index
    3. can store JSON format userId Content-1,{avatars:["Aaa.png", "Bbb.png"]}
    4. Or use MongoDB for these document-type
    5. Merge the 8 graphs into a single store and split on the client side. This can reduce the number of requests to the server. Because the business of changing the avatar is much less than the avatar picture.

Now answer your question: How to build a table is appropriate?

If the function of the product is no longer changed (8 picture picture), then the second article is not suitable;
Then if the user's profile is included with the Avatar (the results of each query will include the Avatar), then fourth is inappropriate because it involves crossing different database types, while querying for personal data is often a frequent operation in social software.
If Avatar is to be associated with other tables in the design of the database, then the third one is very egg-sore.

Here's another scenario:
If the avatar does not necessarily consist of 8 graphs, it could be 4 graphs, maybe 9 graphs, then the design of the first article is not possible
If the number of online users is very high, pull the avatar picture very frequently, then 5th, compared to other ways of operating costs less

This means that the design may have a perfect design, but it does not necessarily suit your needs at that time. You may have only 1000 people in the online number, but you have to divide the table read and write separation, this is not the egg pain.
Please do not over-design!

Which means that what I said above is nonsense ... Because I didn't answer your question.
You still have to follow your understanding of the business itself and the expectations of the data to choose the model that best suits you

There are too many solutions.

1. Use relational database

Since users and Avatars are a one-to-many relationship, it is common practice to create two tables to describe the relationship.

2, the image of the file name on the fuss

In the image file name with a specific keyword to identify the different pictures, which one to use to splice which image of the URL is good.

Many methods:
Stitching URL, eight images each name is placed in a different file name. Do not save the database, according to the membership ID or membership name to create a folder to save co-image.
There is a field in which the image field is uniformly formatted with data. such as JSON.

If 8 images are cropped from a picture, the original can be uploaded to the cloud storage of seven cows, define the image style to be taken, and use its image processing to take the line. The database only has the original image information, the picture style can be written in the configuration file.

Say an alternative solution, with seven cow cloud storage service, take the picture when the required size will be automatically converted

I don't know what the problem is. Why do eight avatars exist in the database?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.