Tag Archives: MySQL

“Mysql Server has gone away” (Solved)

It’s said there are two main causes and solutions:

1) Server timed out and closed the connection.

2) Server dropped an incorrect or too large packet.

I changed these two places in the file “mysql/bin/my.ini”:

find:
innodb_lock_wait_timeout = 50
max_allowed_packet = 6M

change to:
innodb_lock_wait_timeout = 500
max_allowed_packet = 128M

reboot MySQL and Apache, problem is solved.

UPDATE COMMENTS of TABLE AND COLUMNS IN MySQL

Update the comment of a table (i.e.:your_tablename) :

ALTER TABLE your_tablename COMMENT = ‘new comment’;

Update the comment of a column (i.e.:some_column_name) in a table:

ALTER TABLE your_tablename CHANGE COLUMN some_column_name
some_column_name TYPE COMMENT ‘new comment’;

For example:

ALTER TABLE YOUR_TABLENAME CHANGE COLUMN some_column_name
some_column_name mediumint(3) COMMENT ‘new comment’;

Show the COMMENTS in a table (i.e.:your_tablename) :

SHOW CREATE TABLE your_tablename;

Create triggers in phpMyAdmin

Open phpMyAdmin, and then click “SQL” tab to open its webpage, and then put in the sentences as below:

CREATE TRIGGER trigger1 AFTER INSERT ON table1
FOR EACH ROW BEGIN
INSERT INTO table2 SET t2_id = NEW.t1_id;
END;

Note: change “;” to “//” in the space behind “Delimiter”.

This trigger inserts a new record when table1 is inserted in a new record, and set the value of t2_id of the new record in table 2 to the value of new record of t1_id of table 1.

At the beginning, I used the sentence below, and the value of t2_id always 1. It works well until I

delete “and sum =1“.

A trigger example for deleting:

CREATE TRIGGER `trigger2` AFTER DELETE ON `table1`
FOR EACH ROW BEGIN
     DELETE FROM table2 WHERE t2_id = OLD.t1_id;
     UPDATE table3 SET sum = sum+1 WHERE t3_id = NEW.t1_id;
END;
 
The example below is to caculate the records of the old_table and transfer its result to new_table:

INSERT INTO new_table 
SELECT *
FROM (select ” as id, gid, count(gid) as sum from old_table group by gid) as aa 

The examples all works perfectly in my computer, but when I transferred them on the web hosting space,

I found that my account has no super privilege to use triggers and I have to delete them all.