0%

问题sql背景:项目有6个表的要根据pid字段要写入对应的brand_id字段。但是这个其中有两个表是千万级别的。我的worker运行之后,线上的mysql主从同步立刻延迟了!运行了一个多小时之后,居然延迟到了40分钟,而且只更新了十几万行数据。

阅读全文 »

1
2
3
4
5
6
7
SELECT
*
FROM
information_schema.TABLES
WHERE
TABLE_SCHEMA = '{db_name}'
AND table_name = '{tab_name}';
1
2
3
4
5
6
7
SELECT
concat(round(sum( data_length / 1024 / 1024 ),2 ),'MB' )
FROM
information_schema.PARTITIONS
WHERE
table_schema = 'db_name'
AND table_name = 'tab_name';

1
source   d:/myprogram/database/db.sql

导入sql文件过慢,解决办法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
mysql -u root -p -h 127.0.0.1
mysql>use cloud_followup_gfe;
Database changed

mysql> set global innodb_flush_log_at_trx_commit=0;
Query OK, 0 rows affected (0.03 sec)

mysql> set global max_allowed_packet=1024*1024*20;
Query OK, 0 rows affected (0.00 sec)

mysql> set global bulk_insert_buffer_size=32*1024*1024;
Query OK, 0 rows affected (0.00 sec)

mysql> set global innodb_buffer_pool_size=32*1024*1024;
Query OK, 0 rows affected, 1 warning (0.09 sec)

>mysql source /root/test.sql

sql injection violation, multi-statement not allow

数据库连接url加上支持批量的参数allowMultiQueries=true

如果用了druid,并且使用了wall-filter,需要配置

LEFT(str,len)

Returns the leftmost len characters from the string str, orNULLif any argument isNULL.

1
2
mysql> SELECT LEFT('foobarbar', 5);
-> 'fooba'

This function is multibyte safe.