Mysql Insert를 1 행씩 하다 보니 성능이 너무 저질이라… insert into table values (),(),()…()
의 문법을 사용해서 하려고 했는데.. 데이터를 좀 많이 넣으니.. 아래와 같은 오류가 출력되었습니다.
com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1146237 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2584)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1554)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3170)
at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1316)
at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1235)
at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:225)
at org.springframework.jdbc.core.JdbcTemplate$1UpdateStatementCallback.doInStatement(JdbcTemplate.java:457)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:341)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:467)
한번에 실행할 수 있는 패킷의 양이 정해져 있습니다. 덤으로 콘솔 로그를 무한으로 찍해 놓은 저의 PC도 먹통이 된것 처럼 느려지게 되었습니다. 이클립스 콘솔로그 사이즈를 정해야 겠습니다.
쿼리를 통해 조회해 보니
mysql> show variables like ‘max%’;
+—————————-+———————-+
| Variable_name | Value |
+—————————-+———————-+
| max_allowed_packet | 1048576 |
| max_binlog_cache_size | 4294963200 |
| max_binlog_size | 1073741824 |
| max_connect_errors | 10 |
| max_connections | 100 |
| max_delayed_threads | 20 |
| max_error_count | 64 |
| max_heap_table_size | 16777216 |
| max_insert_delayed_threads | 20 |
| max_join_size | 18446744073709551615 |
| max_length_for_sort_data | 1024 |
| max_prepared_stmt_count | 16382 |
| max_relay_log_size | 0 |
| max_seeks_for_key | 4294967295 |
| max_sort_length | 1024 |
| max_sp_recursion_depth | 0 |
| max_tmp_tables | 32 |
| max_user_connections | 0 |
| max_write_lock_count | 4294967295 |
+—————————-+———————-+
19 rows in set (0.00 sec)
mysql>
mysql>
mysql> set global max_allowed_packet= 1024*1024*32;
Query OK, 0 rows affected (0.02 sec)
32M 로 설정 완료.. 다시 실행 해봅시다.