How much data can be stored in a MySQL table?

How much data can be stored in a MySQL table?

MySQL itself does not impose a limit on the maximum number of records in a single table. This value depends on the limit of your operating system on a single file. Rumor in the industry is 5 million lines. If there are more than 5 million rows, consider splitting tables and databases. Alibaba's "Java Development Manual" states that database and table sharding is only recommended when the number of rows in a single table exceeds 5 million or the capacity of a single table exceeds 2GB.

A simple test
inserts data into the table through a loop, records the number of inserted items, and outputs it to the console.

private static void insertDataDemo() {
    
    
		DButil dButil = new DButil();
		myCon = dButil.getConnection();
		try {
    
    
			int i = 0;
			while(1==1) {
    
    
				i++;
				String sql = "insert into users (user_name,user_password)"
						+ " value ('"+i+"','password')";
				sta = myCon.createStatement();
				sta.execute(sql);
				System.out.println(i);
			}
		} catch (Exception e) {
    
    
			e.printStackTrace();
		}finally {
    
    
			dButil.close();
		}
	}

Result: After a night of operation, I found in the morning that more than two million piecesInsert image description here
of data had been inserted . Although data could still be inserted, the console output showed that the speed of inserting data was relatively slow, inserting every 2-3 seconds. One thing, this speed is unbearable.

In fact, the maximum amount of data that can be stored in a MySql database table has nothing to do with the actual number of records, but is related to the configuration of MySQL and the hardware of the machine . Because, in order to improve performance, MySQL will load the index of the table into memory. When the InnoDB buffer size is sufficient, it can be fully loaded into memory and there will be no problem with querying. However, when a single-table database reaches an upper limit of a certain magnitude, the memory cannot store its index, causing subsequent SQL queries to generate disk IO, resulting in performance degradation. Of course, this is also related to the design of the specific table structure, and the ultimate problem is memory limitation.

Guess you like

Origin blog.csdn.net/weixin_40307206/article/details/105158912