+----------+-------------+------+-------+---------+-------+| Field | Type | Null | Key | Default | Extra |+----------+-------------+------+-------+---------+-------+| siteid | int(11) | No | true | 10 | || citycode | smallint(6) | No | true | N/A | || username | varchar(32) | No | true | | || pv | bigint(20) | No | false | 0 | SUM |+----------+-------------+------+-------+---------+-------+
ALTER TABLE table1 ADD COLUMN uv BIGINT SUM DEFAULT '0' after pv;
After successful submission, you can check the job progress with the following command:
SHOW ALTER TABLE COLUMN;
When the job status is FINISHED, it indicates that the job is complete.
After the ALTER TABLE is completed, you can use DESC TABLE to view the latest Schema.mysql> DESC table1;+----------+-------------+------+-------+---------+-------+| Field | Type | Null | Key | Default | Extra |+----------+-------------+------+-------+---------+-------+| siteid | int(11) | No | true | 10 | || citycode | smallint(6) | No | true | N/A | || username | varchar(32) | No | true | | || pv | bigint(20) | No | false | 0 | SUM || uv | bigint(20) | No | false | 0 | SUM |+----------+-------------+------+-------+---------+-------+5 rows in set (0.00 sec)
CANCEL ALTER TABLE COLUMN FROM table1.
For more help, see HELP ALTER TABLE.+----------+-------------+------+-------+---------+-------+| Field | Type | Null | Key | Default | Extra |+----------+-------------+------+-------+---------+-------+| siteid | int(11) | No | true | 10 | || citycode | smallint(6) | No | true | N/A | || username | varchar(32) | No | true | | || pv | bigint(20) | No | false | 0 | SUM || uv | bigint(20) | No | false | 0 | SUM |+----------+-------------+------+-------+---------+-------+
ALTER TABLE table1 ADD ROLLUP rollup_city(citycode, pv);
After successful submission, you can check the job progress with the following command: SHOW ALTER TABLE ROLLUP;. When the job status is FINISHED, it indicates that the job is complete.
After the Rollup is created, you can use DESC table1 ALL to view the Rollup information of the table.mysql> desc table1 all;+-------------+----------+-------------+------+-------+--------+-------+| IndexName | Field | Type | Null | Key | Default | Extra |+-------------+----------+-------------+------+-------+---------+-------+| table1 | siteid | int(11) | No | true | 10 | || | citycode | smallint(6) | No | true | N/A | || | username | varchar(32) | No | true | | || | pv | bigint(20) | No | false | 0 | SUM || | uv | bigint(20) | No | false | 0 | SUM || | | | | | | || rollup_city | citycode | smallint(6) | No | true | N/A | || | pv | bigint(20) | No | false | 0 | SUM |+-------------+----------+-------------+------+-------+---------+-------+8 rows in set (0.01 sec)
CANCEL ALTER TABLE COLUMN FROM table1
After the Rollup is created, queries do not need to specify the Rollup to be used. The system will automatically determine whether to use the Rollup. You can check whether the Rollup is being used by executing the command EXPLAIN your_sql;.
For more help, see HELP ALTER TABLE.Memory limit exceeded error, it usually means the memory limit has been exceeded. When the memory exceeds the limit, users should try to resolve it by optimizing their SQL statements. If the 2GB memory is insufficient, you can manually set memory parameters.
Display query memory limits:mysql> SHOW VARIABLES LIKE "%mem_limit%";+---------------+------------+| Variable_name | Value |+---------------+------------+| exec_mem_limit| 2147483648 |+---------------+------------+1 row in set (0.00 sec)
exec_mem_limit is byte. You can use the SET command to change the value of exec_mem_limit. For example, set it to 8GB.
SET exec_mem_limit = 8589934592;mysql> SHOW VARIABLES LIKE "%mem_limit%";+---------------+------------+| Variable_name | Value |+---------------+------------+| exec_mem_limit| 8589934592 |+---------------+------------+1 row in set (0.00 sec)
SET GLOBAL exec_mem_limit = 8589934592;. After the settings are completed, disconnect the session and log in again for the parameter to take effect permanently.mysql> SHOW VARIABLES LIKE "%query_timeout%";+---------------+-------+| Variable_name | Value |+---------------+-------+| QUERY_TIMEOUT | 300 |+---------------+-------+1 row in set (0.00 sec)
SET query_timeout = 60;SET GLOBAL to apply the change globally.mysql> select sum(table1.pv) from table1 join table2 where table1.siteid = 2;+--------------------+| sum(table1.pv) |+--------------------+| 10 |+--------------------+1 row in set (0.20 sec)
mysql> select sum(table1.pv) from table1 join [broadcast] table2 where table1.siteid = 2;+--------------------+| sum(table1.pv) |+--------------------+| 10 |+--------------------+1 row in set (0.20 sec)
mysql> select sum(table1.pv) from table1 join [shuffle] table2 where table1.siteid = 2;+--------------------+| sum(table1.pv) |+--------------------+| 10 |+--------------------+1 row in set (0.15 sec)
jdbc:mysql://[host:port],[host:port].../[database][?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...
http://dev.mysql.com/doc/refman/5.6/en/mysql-proxy-using.htmlFeedback