mysqlbinlog doesn't work in Google Cloud SQL MySql - mysql

I have MySql instance on Google Cloud SQL. I have enabled binary logs. I can check the log files, as shown below.
mysql> SHOW BINARY LOGS;
+------------------+-----------+-----------+
| Log_name | File_size | Encrypted |
+------------------+-----------+-----------+
| mysql-bin.000001 | 1375216 | No |
| mysql-bin.000002 | 7336055 | No |
+------------------+-----------+-----------+
I am able to check the events also in logs file.
mysql> SHOW BINLOG EVENTS IN 'mysql-bin.000001' limit 5;
+------------------+-----+----------------+-----------+-------------+-------------------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+------------------+-----+----------------+-----------+-------------+-------------------------------------------------------------------+
| mysql-bin.000001 | 4 | Format_desc | 883641454 | 124 | Server ver: 8.0.18-google, Binlog ver: 4 |
| mysql-bin.000001 | 124 | Previous_gtids | 883641454 | 155 | |
| mysql-bin.000001 | 155 | Gtid | 883641454 | 234 | SET ##SESSION.GTID_NEXT= 'd635d876-06de-11eb-b2ab-42010a9d0043:1' |
| mysql-bin.000001 | 234 | Query | 883641454 | 309 | BEGIN |
| mysql-bin.000001 | 309 | Table_map | 883641454 | 367 | table_id: 81 (mysql.heartbeat) |
+------------------+-----+----------------+-----------+-------------+-------------------------------------------------------------------+
But it gives me error when I use the mysqlbinlog command.
mysql> mysqlbinlog mysqld-bin.000001;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysqlbinlog mysqld-bin.000001' at line 1
I don't understand what is going wrong here. Please help.

On cloud shell install :
sudo apt-get install mysql-server
Install the Cloud SQL Proxy client on your local machine
Then run :
mysqlbinlog -R --protocol TCP --host localhost --user root --password --port 3306 mysqld-bin.000001;

Related

ERROR 2013 (HY000): Lost connection to MySQL during query

I have a remote MySQL database, and my deployed application (a few java microservice applications) consistently encounters the error ERROR 2013 (HY000): Lost connection to MySQL during query with some SQL queries. Then I tried to connect to mysql with MySQL command line client, executed the same query, and I managed to replicate the same error. Below is Mysql setup after following this page https://dev.mysql.com/doc/refman/5.7/en/error-lost-connection.html
+------------------------------+----------+
| Variable_name | Value |
+------------------------------+----------+
| connect_timeout | 3600 |
| delayed_insert_timeout | 300 |
| have_statement_timeout | YES |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 5 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 7200 |
| lock_wait_timeout | 50 |
| net_read_timeout | 3000 |
| net_write_timeout | 6000 |
| rpl_semi_sync_master_timeout | 10000 |
| rpl_stop_slave_timeout | 31536000 |
| slave_net_timeout | 4 |
| wait_timeout | 7200 |
+------------------------------+----------+
+--------------------------+------------+
| Variable_name | Value |
+--------------------------+------------+
| max_allowed_packet | 1073741824 |
| slave_max_allowed_packet | 1073741824 |
+--------------------------+------------+
However, I systematically have the same error after roughly 10 minutes after executing a big SQL query from the mysql command line client.
Note: On the DB server side, I notice the log [Note] Aborted connection xxxxx to db: 'xxxxx' user 'xxxxx' host 'xxxxx' (Got an error writing communication packets)
DBA executed the query successfully on the server on which mysql is installed. But we have to use mysql remotely as a service.
I will be grateful if anybody can help.
Finally, the root cause was a network issue. Our remote MySQL instance is exposed as service. There's an additional proxy between the client and MySQL DB. By default, the connection will be closed if no communication between client and server over 10 mins.

xtrabackup does not write gtid information in xtrabackup_binlog_info

Software versions:
xtrabackup 8.0.12
percona-xtradb-cluster-server 8.0.18-9
I am running xtrabackup with this options:
--defaults-file=/etc/mysql/my.cnf --backup --user=backup
--password=**** --parallel=4 --no-timestamp --target-dir=/my-backup-dir
Some of server options:
binlog_format | ROW
gtid_mode | ON_PERMISSIVE
enforce_gtid_consistency | ON
File xtrabackup_binlog_info has only binlog file name and position:
mysql-bin.000159 251
No GTID, so I can not create GTID-based replication restoring a slave from this backup.
What should I do to make xtrabackup include this information?
UPDATE:
Check if GTIDs are enabled:
show global variables like '%gtid%';
| Variable_name | Value |
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed | c0e3de06-a2a6-11ea-913c-c7b046cf5782:1-3399594,
de211648-2642-ee18-628d-dc48283b005c:1-3697598:3877279-10141440 |
| gtid_executed_compression_period | 1000 |
| gtid_mode | ON_PERMISSIVE |
| gtid_owned | |
| gtid_purged | c0e3de06-a2a6-11ea-913c-c7b046cf5782:1-2661056,
de211648-2642-ee18-628d-dc48283b005c:1-3697598:3877279-10141440 |
| session_track_gtids | OFF |
show master status;
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
| mysql-bin.000166 | 15285372 | | | c0e3de06-a2a6-11ea-913c-c7b046cf5782:1-3358798,
de211648-2642-ee18-628d-dc48283b005c:1-3697598:3877279-10141440 |
(pavel.selivanov#localhost) [kassa_prod]> show binlog events in 'mysql-bin.000166' limit 7;
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info
| mysql-bin.000166 | 4 | Format_desc | 4315 | 124 | Server ver: 8.0.18-9, Binlog ver: 4 |
| mysql-bin.000166 | 124 | Previous_gtids | 4315 | 251 | c0e3de06-a2a6-11ea-913c-c7b046cf5782:1-3347159,
de211648-2642-ee18-628d-dc48283b005c:3697598:3877279-10141440 |
| mysql-bin.000166 | 251 | Gtid | 4315 | 330 | SET ##SESSION.GTID_NEXT= 'c0e3de06-a2a6-11ea-913c-c7b046cf5782:3347160' |
| mysql-bin.000166 | 330 | Query | 4315 | 411 | BEGIN |
| mysql-bin.000166 | 411 | Table_map | 4315 | 499 | table_id: 150 (db.table) |
| mysql-bin.000166 | 499 | Update_rows | 4315 | 3475 | table_id: 150 flags: STMT_END_F |
| mysql-bin.000166 | 3475 | Xid | 4315 | 3506 | COMMIT /* xid=9611331 */
From the manual:
ON_PERMISSIVE: New transactions are GTID transactions. Replicated transactions can be either anonymous or GTID transactions.
Check with show global variables like 'gt%'; or in your binary logs, if you actually have GTID transactions.
You actually don't have anything special to do, to have xtrabackup include GTIDs in the xtrabackup_binlog_info file: How to create a new (or repair a broken) GTID based slave

MySQL Group Replication plugin not found in version 5.7.19, 5.7.21

I am attempting to enable the MySQL group replication plugin on MySQL 5.7.21, which should be available in 5.7 as per the documentation (https://dev.mysql.com/doc/refman/5.7/en/group-replication.html)
$ mysql --version
mysql Ver 14.14 Distrib 5.7.21, for Linux (x86_64) using EditLine wrapper
When I attempt to enable the plugin through MySQL:
$ mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';
ERROR 1126 (HY000): Can't open shared library '/usr/lib/mysql/plugin/group_replication.so' (errno: 2 /usr/lib/mysql/plugin/group_replication.so: cannot open shared object file: No such file or directory)
The output of my plugins in MySQL:
$ mysql> SHOW PLUGINS;
+----------------------------+----------+--------------------+---------+---------+
| Name | Status | Type | Library | License |
+----------------------------+----------+--------------------+---------+---------+
| binlog | ACTIVE | STORAGE ENGINE | NULL | GPL |
| mysql_native_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| sha256_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| CSV | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MEMORY | ACTIVE | STORAGE ENGINE | NULL | GPL |
| InnoDB | ACTIVE | STORAGE ENGINE | NULL | GPL |
| INNODB_TRX | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_LOCKS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_LOCK_WAITS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP_RESET | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMPMEM | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMPMEM_RESET | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP_PER_INDEX | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP_PER_INDEX_RESET | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_BUFFER_PAGE | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_BUFFER_PAGE_LRU | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_BUFFER_POOL_STATS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_TEMP_TABLE_INFO | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_METRICS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_DEFAULT_STOPWORD | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_DELETED | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_BEING_DELETED | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_CONFIG | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_INDEX_CACHE | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_INDEX_TABLE | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_TABLES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_TABLESTATS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_INDEXES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_COLUMNS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_FIELDS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_FOREIGN | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_FOREIGN_COLS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_TABLESPACES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_DATAFILES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_VIRTUAL | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| MyISAM | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MRG_MYISAM | ACTIVE | STORAGE ENGINE | NULL | GPL |
| PERFORMANCE_SCHEMA | ACTIVE | STORAGE ENGINE | NULL | GPL |
| ARCHIVE | ACTIVE | STORAGE ENGINE | NULL | GPL |
| BLACKHOLE | ACTIVE | STORAGE ENGINE | NULL | GPL |
| FEDERATED | DISABLED | STORAGE ENGINE | NULL | GPL |
| partition | ACTIVE | STORAGE ENGINE | NULL | GPL |
| ngram | ACTIVE | FTPARSER | NULL | GPL |
+----------------------------+----------+--------------------+---------+---------+
44 rows in set (0.01 sec)
This is the contents of the plugin directory:
$ ls -lah /usr/lib/mysql/plugin/
total 644K
drwxr-xr-x 2 root root 4.0K Sep 26 23:24 .
drwxr-xr-x 3 root root 4.0K Sep 26 23:24 ..
-rw-r--r-- 1 root root 21K Jul 19 14:10 adt_null.so
-rw-r--r-- 1 root root 6.2K Jul 19 14:10 auth_socket.so
-rw-r--r-- 1 root root 44K Jul 19 14:10 connection_control.so
-rw-r--r-- 1 root root 107K Jul 19 14:10 innodb_engine.so
-rw-r--r-- 1 root root 79K Jul 19 14:10 keyring_file.so
-rw-r--r-- 1 root root 151K Jul 19 14:10 libmemcached.so
-rw-r--r-- 1 root root 9.7K Jul 19 14:10 locking_service.so
-rw-r--r-- 1 root root 11K Jul 19 14:10 mypluglib.so
-rw-r--r-- 1 root root 6.2K Jul 19 14:10 mysql_no_login.so
-rw-r--r-- 1 root root 55K Jul 19 14:10 rewriter.so
-rw-r--r-- 1 root root 56K Jul 19 14:10 semisync_master.so
-rw-r--r-- 1 root root 15K Jul 19 14:10 semisync_slave.so
-rw-r--r-- 1 root root 27K Jul 19 14:10 validate_password.so
-rw-r--r-- 1 root root 31K Jul 19 14:10 version_token.so
These are the contents of my config:
cat /etc/mysql/my.cnf
[mysqld_safe]
nice = 0
socket = /var/run/mysqld/mysqld.sock
[mysqld]
basedir = /usr
bind_address = 123.45.67.89
binlog_checksum = NONE
binlog_format = ROW
datadir = /var/lib/mysql
enforce_gtid_consistency = ON
expire_logs_days = 10
general_log = 1
general_log_file = /var/log/mysql/mysql.log
gtid_mode = ON
key_buffer_size = 8388608
lc_messages_dir = /usr/share/mysql
log_bin = binlog
log_error = /var/log/mysql/mysql_error.log
log_slave_updates = ON
long_query_time = 60
loose-group_replication_bootstrap_group = OFF
loose-group_replication_enforce_update_everywhere_checks= ON
loose-group_replication_group_name = 34dee7cd-d20d-4f59-9500-f56ada9a1abz
loose-group_replication_group_seeds = 123.45.67.88:33061,123.45.67.89:33061
loose-group_replication_ip_whitelist = 123.45.67.88,123.45.67.89
loose-group_replication_local_address = 123.45.67.89:33061
loose-group_replication_recovery_use_ssl= 1
loose-group_replication_single_primary_mode= OFF
loose-group_replication_ssl_mode = REQUIRED
loose-group_replication_start_on_boot = OFF
master_info_repository = TABLE
max_allowed_packet = 16M
max_binlog_size = 100M
max_connect_errors = 100000000
pid-file = /var/run/mysqld/mysqld.pid
port = 3306
query_cache_limit = 1M
query_cache_size = 16M
relay_log = my-project-prod-relay-bin
relay_log_info_repository = TABLE
report_host = 123.45.67.88
require_secure_transport = ON
server_id = 2
skip_external_locking
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow-query.log
socket = /var/run/mysqld/mysqld.sock
thread_cache_size = 8
thread_stack = 192K
tmpdir = /tmp
transaction_write_set_extraction = XXHASH64
user = mysql
[mysqldump]
max_allowed_packet = 16M
quick
quote_names
[mysql]
no-auto-rehash
[isamchk]
key_buffer_size = 16M
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
!includedir /etc/mysql/conf.d/
I'm wondering if I'm using the wrong version of MySQL or if there is some other step needed to install the group replication plugin?
FWIW I downloaded 5.7.19 Community Edition
https://dev.mysql.com/doc/refman/5.7/en/group-replication.html to run it in a sandbox, and I confirm that the group replication .so file is present.
I got the plugin to load with the INSTALL PLUGIN statement, just like you tried.
First I had to add some config settings, which are documented in https://dev.mysql.com/doc/refman/5.7/en/group-replication-configuring-instances.html
server_id=1 # or any value unique among your replica set
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
log_bin=binlog
binlog_format=ROW
And of course restart mysqld after editing the config settings.
According to discussion here, it looks like the group replication plugin may have been intentionally left out of the normal MySQL server edition.
To know if you are running the Community Edition, run mysql:
> mysql -u root -p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20-log MySQL Community Server (GPL)
.....
To manually install the Community Edition 5.7 (or other archived versions here: https://downloads.mysql.com/archives/community/), run the following commands:
sudo apt-get install libaio1
sudo apt-get install libmecab2
curl -OL https://downloads.mysql.com/archives/get/file/mysql-common_5.7.20-1ubuntu16.04_amd64.deb
curl -OL https://downloads.mysql.com/archives/get/file/mysql-community-client_5.7.20-1ubuntu16.04_amd64.deb
curl -OL https://downloads.mysql.com/archives/get/file/mysql-client_5.7.20-1ubuntu16.04_amd64.deb
curl -OL https://downloads.mysql.com/archives/get/file/mysql-community-server_5.7.20-1ubuntu16.04_amd64.deb
sudo dpkg -i mysql-common_5.7.20-1ubuntu16.04_amd64.deb
sudo dpkg -i mysql-community-client_5.7.20-1ubuntu16.04_amd64.deb
sudo dpkg -i mysql-client_5.7.20-1ubuntu16.04_amd64.deb
sudo dpkg -i mysql-community-server_5.7.20-1ubuntu16.04_amd64.deb
Bumped into the same issue. Bill's answer and the link to why it's not included in the standard version pointed me in the right direction, then I found Luis' answer here. The linked guide shows that after installing mysql-apt-config, apt-get install mysql-server fetches the community version by default. This allowed me to proceed with installing the plugin, although I had an extra error:
ERROR 1123 (HY000): Can't initialize function 'group_replication'; Plugin initialization function failed.
When I checked /var/log/mysql/error.log, I saw it fails because:
2018-07-04T14:19:36.039987Z 5 [ERROR] For the creation of replication channels the master info and relay log info repositories must be set to TABLE
Providing the right Group Replication-ready configuration to MySQL solved it. In my case that was simply restarting the MySQL server since I had provisioned it with Ansible but it hadn't taken effect. Hope that helps anyone dealing with Group Replication.
EDIT: While the above works, it created problems when using the Geerlingguy Ansible role, so instead of installing Community Server, I ended up provisioning the plugin directly with the following Ansible code:
- name: Provision the MySQL group_replication plugin
copy:
src: group_replication.so
dest: /usr/lib/mysql/plugin/group_replication.so
mode: 0644
I got the plugin from the community version of MySQL though, but I can say it's another valid approach that's better suited to some situations.

MySQL Connections causing server went away, nothing in processlist

I have a large amount of connections but when I issue a show full processlist I am not showing anything close to the connections I see. Are these connections orphans of some sort? I tried the flush hosts command and the connections persist, even with a reboot of the server and also restarting the mysql server.
I believe these connections are causing issues with making new connections to the database. User's are getting a "server went away" error. How do I clear these?
See commands below:
mysql> show status like '%onn%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| Aborted_connects | 5 |
| Connections | 11743 |
| Max_used_connections | 24 |
| Ssl_client_connects | 0 |
| Ssl_connect_renegotiates | 0 |
| Ssl_finished_connects | 0 |
| Threads_connected | 6 |
+--------------------------+-------+
7 rows in set (0.00 sec)
mysql> show full processlist;
+-------+---------+----------------------+--------------------+---------+-------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-------+---------+----------------------+--------------------+---------+-------+-------+-----------------------+
| 4494 | rode | localhost:43411 | NULL | Sleep | 11159 | | NULL |
| 4506 | rode | localhost:43423 | information_schema | Sleep | 11159 | | NULL |
| 4554 | rode | localhost:43511 | performance_schema | Sleep | 11112 | | NULL |
| 11500 | ass | serv:1243 | Home-Tech | Sleep | 0 | | NULL |
| 11743 | root | localhost | NULL | Query | 0 | NULL | show full processlist |
| 11744 | ass | out:6070 | Home-Tech | Sleep | 4 | | NULL |
| 11745 | ass | out:6074 | HTGlobal | Sleep | 8 | | NULL
The MySQL server has gone away (error 2006) has two main causes
Server timed out and closed the connection. To fix, check that “wait_timeout” mysql variable in your my.cnf configuration file is large enough.
Server dropped an incorrect or too large packet. If mysqld gets a packet that is too large or incorrect, it assumes that something has gone wrong with the client and closes the connection. To fix, you can increase the maximal packet size limit “max_allowed_packet” in my.cnf file, eg. set max_allowed_packet = 128M, then sudo /etc/init.d/mysql restart.
there are two main ways to fix this. if the above change doesn't there may be an issue with your linux or windows mysql database server; you either need to increase ram on your server or watch it's process.
is this on a windows or linux box?

Shell Script to auto kill mysql sleep processes

How We Kill mysql sleep processes Like:
+------+-----------+-----------+------------------------+---------+------+----------------+-------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+------+-----------+-----------+------------------------+---------+------+----------------+-------------------------------------------------------------------------------------------+
| 2477 | stageuser | localhost | jj_production_11102013 | Query | 0 | end | SELECT * FROM wp_comments WHERE blog_id = 1071 ORDER BY comment_date_gmt DESC LIMIT 0, 50 |
| 3050 | stageuser | localhost | jj_production_11102013 | Query | 0 | Sorting result | SELECT * FROM wp_comments WHERE blog_id = 1071 ORDER BY comment_date_gmt DESC LIMIT 0, 50 |
| 3052 | stageuser | localhost | jj_production_11102013 | Sleep | 336 | | NULL |
| 3056 | stageuser | localhost | NULL | Query | 0 | NULL | show processlist |
| 3057 | stageuser | localhost | jj_production_11102013 | Sleep | 301 | | NULL |
| 3058 | stageuser | localhost | jj_production_11102013 | Sleep | 299 | | NULL |
| 3059 | stageuser | localhost | jj_production_11102013 | Sleep | 298 | | NULL |
| 3061 | stageuser | localhost | jj_production_11102013 | Sleep | 273 | | NULL |
| 3068 | stageuser | localhost | jj_production_11102013 | Sleep | 251 | | NULL |
| 3072 | stageuser | localhost | jj_production_11102013 | Sleep | 233 | | NULL |
| 3111 | stageuser | localhost | jj_production_11102013 | Sleep | 1 | | NULL |
+------+-----------+-----------+------------------------+---------+------+----------------+-------------------------------------------------------------------------------------------+
11 rows in set (0.00 sec)
Is this sleep processes affect site performance like slow other queries?
I made it.
Create kill_sleep.sh file
mysql -u<user> -p<password> -h<host> -e "select concat('KILL ',id,';') into outfile '/tmp/sleep_processes.txt' from information_schema.processlist where Command = 'Sleep'"
mysql -u<user> -p<password> -h<host> -e "source /tmp/sleep_processes.txt;"
rm -rf /tmp/sleep_processes.txt
And set kill_sleep.sh to cron job .
Vishal's answer works well if you're running the command on the MySQL server, but it won't work if you're connecting to the server remotely or if you don't have permission to run SOURCE or SELECT ... INTO OUTFILE (eg. Amazon's RDS). It's possible to rewrite it not to rely on those features though, and then it'll work anywhere:
mysql -h<host> -u<user> -p -e "SELECT CONCAT('KILL ',id,';') FROM information_schema.processlist WHERE Command = 'Sleep'" > sleep.txt
cat sleep.txt | xargs -I% mysql -h<host> -u<user> -p -e "%"
The syntax is:
KILL thread_id
In your case:
mysql > KILL 3057
But in order to delete all the sleep processes,one command cant be used, you need to loop through whole processlist,after taking all the processes in tmp table and looping through it:
select concat('KILL ',id,';') from information_schema.processlist where Command='Sleep';
select concat('KILL ',id,';') from information_schema.processlist where Command='Sleep' into outfile '/tmp/a.txt';
Referred from here
A easy way:
for i in `mysql -e "show processlist" | awk '/Sleep/ {print $1}'` ; do mysql -e "KILL $i;"; done
Percona Tools:
pt-kill --match-command Sleep --idle-time 100 --victims all --interval 30 --kill
This will find all connections that are "Sleep" state and idle for 100 seconds or more and kill them. --interval 30 will make it keep do this every 30 seconds. So you can open a screen -S ptkill then in that screen run the above command, then ctrl-A, D to detach and exit the terminal and it will just keep running cleaning up your connections.
https://www.percona.com/doc/percona-toolkit/2.1/pt-kill.html