This article mainly introduces Mysql database sub-database and sub-table method (commonly used), involves the knowledge of MySQL database, and friends who are interested in the knowledge of MySQL database sub-database and sub-table, let's learn together
1 library
1.1 Sub-libraries by function
Divide by function. Commonly divided into 6 major libraries:
1 User class library: used to save the relevant information of the user. For example: db_user, db_system, db_company, etc.
2 Business class library: used to save the main business information. For example, the main business is jokes, use this library to save joke business. For example: db_joke, db_temp_joke, etc.
3 Memory class library: mainly use Mysql's memory engine. The data in the foreground is searched from the memory library, which is fast. For example: heap.
4 Picture library: It mainly saves the index and association of pictures. For example: db_img_index, db_img_res.
5 Log library: record click, refresh, login and other log information. For example: db_log_click, db_log_fresh, db_log_login.
6 Statistics library: Statistics on business, such as clicks, refreshes, etc. For example db_stat.
1.2 Install the city station sub-library
If the business is all over the country, the library is divided according to the function, and each city copies an exact same library, but the library suffix is the city name. For example db_log_click_bj, db_log_click_tj, db_log_click_sh;
2 points table
2.1 Sub-table according to the number of users or services
For users or services, they can be divided into n tables according to the number %n.
For example: joke sheet.
tb_joke_01,tb_joke_02,tb_joke_03,tb_joke_04........
2.2 Divide the table by date
For tables of log or statistics classes, etc. It can be divided by year, month, day and week.
For example, click traffic statistics.
1
|
tb_click_stat_201601,tb_click_stat_201602,tb_click_stat_201603
|
3 Mysql database common architecture
Core: One master and multiple slaves, read and write separation.