Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I executed an incorrect SQL command:

SET GLOBAL init_connect='SET CHARACTER SET=utf-8';

Now, when I try and run a script that connects to this database, I get the following error: _mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away').

How would I reset the global init_connect values?

share|improve this question

1 Answer 1

You need to place init_connect in /etc/my.cnf

[mysqld]
init_connect='SET CHARACTER SET=utf-8';

This will set the variable for you after the next mysql restart.

If your username has the SUPER privilege, you need not set the variable again dynamically since you already set globally earlier with SET GLOBAL init_connect='SET CHARACTER SET=utf-8';

As for 'MySQL server has gone away', the most common cause is timing out. Please set wait_timeout and interactive_timeout to something sufficiently large (default 28800 sec [8 hours]). Other reasons are specified in the MySQL Documentation.

UPDATE 2012-04-22 01:24 EDT

Since you are changing the character set to process multibyte character strings, you may need to make sure the MySQL Packet is bigger (at least triple whatever the configuration is now). I would bump it up to 256M

[mysqld]
init_connect='SET CHARACTER SET=utf-8';
max_allowed_packet=256M

I recommend this because sometimes Error 2006 : 'MySQL server has gone away' is caused by the MySQL Packet not being big enough. I wrote posts about this earlier:

share|improve this answer
    
"you may need to make sure the MySQL Packet is bigger (at least triple whatever the configuration is now)" - I would say that completely depends on what the actual requirement is. In many applichations, the default is by far higher than needed... –  glglgl May 22 '12 at 7:20
    
@glglgl, max_allowed_packet is not allocated in full. It's just an upper limit: only the required memory is allocated (as opposed to, say. sort_buffer_size). So it makes no harm to have this value high. –  Shlomi Noach Aug 20 '12 at 8:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.