Number of DB connections opened - mysql

Can anyone know the way to get the number of DB connection being used , in MYSQL 5.0

SHOW STATUS WHERE variable_name = 'Threads_connected'

12.5.5.31. SHOW PROCESSLIST Syntax
Shows you how many people are connected to the server.

Number of open connections can be found out by using below query:
mysql -e 'SHOW STATUS WHERE variable_name LIKE "Threads_%" OR variable_name = "Connections"'
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Connections | 862 |
| Threads_cached | 0 |
| Threads_connected | 10 |
| Threads_created | 26 |
| Threads_running | 1 |
+-------------------+-------+

Related

Why the error: Neither --relay-log nor --relay-log-index were used

So i have this mysql innodb cluster of 3 mysql instances on docker that is always failing with the error group replication not active.
Looking at the error logs, the only thing i can find is this warning:
Neither --relay-log nor --relay-log-index were used; so replication may break when this MySQL server acts as a slave and has his hostname changed!! Please use '--relay-log=f3353ca0124a-relay-bin' to avoid this problem
I try the following query on the particular mysql instance 'f3353ca0124a'
show variables like '%relay_log%';
and i find
+---------------------------+---------------------------------------------+
| Variable_name | Value |
+---------------------------+---------------------------------------------+
| max_relay_log_size | 0 |
| relay_log | f3353ca0124a-relay-bin |
| relay_log_basename | /var/lib/mysql/f3353ca0124a-relay-bin |
| relay_log_index | /var/lib/mysql/f3353ca0124a-relay-bin.index |
| relay_log_info_file | relay-log.info |
| relay_log_info_repository | TABLE |
| relay_log_purge | ON |
| relay_log_recovery | OFF |
| relay_log_space_limit | 0 |
| sync_relay_log | 10000 |
| sync_relay_log_info | 10000 |
+---------------------------+---------------------------------------------+
11 rows in set (0.11 sec)
So i am confused cos it looks to me that the value which the error suggest i should set is already set.
Please can anyone help show me how to fix this error.

Why did I still get MySQL errno 2013 Lost connection during query error even I had MYSQL_OPT_RECONNECT on

Like setup MySQL connection with MYSQL_OPT_RECONNECT is true in this way
my_bool reconnect = true;
mysql_options(ptrMYSQL, MYSQL_OPT_RECONNECT, &reconnect);
then raised one SELECT immediately, log file shows less than 1ms, performed OK.
295ms later, after did some other work, the process raised another query with the same ptrMYSQL, this one failed for the reason
errno 2013 error Lost connection to MySQL server during query
Since I had the AUTO RECONNECT option on, how can MySQL query failed in such way?
This is what timeout variables look like:
mysql> show variables like '%timeout%';
+------------------------------+-----------+
| Variable_name | Value |
+------------------------------+-----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| have_statement_timeout | YES |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 8 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 1800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| rpl_semi_sync_master_timeout | 999999999 |
| rpl_stop_slave_timeout | 31536000 |
| slave_net_timeout | 30 |
| wait_timeout | 1800 |
+------------------------------+-----------+
14 rows in set (0.00 sec)
And the version:
mysql> select version();
+------------+
| version() |
+------------+
| 5.7.17-log |
+------------+

Mysql 5.5 cannot reconnect after a several minutes

I used mysql 5.5 in my project and encontered a problem that I can't solve. I googled but without result. My client can connect the server normally however after a while about 10 minutes the connection lost. The client would reconnect the server but it hangs up and never return a connection. I tried with two kinds of clients: The native mysql console client and the mysql workbench and same result. Here are some details:
MariaDB [(none)]> show variables like "%timeout%";
+----------------------------+----------+
| Variable_name | Value |
+----------------------------+----------+
| connect_timeout | 10 |
| deadlock_timeout_long | 50000000 |
| deadlock_timeout_short | 10000 |
| delayed_insert_timeout | 300 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| slave_net_timeout | 3600 |
| thread_pool_idle_timeout | 60 |
| wait_timeout | 28800 |
+----------------------------+----------+
so the wait_timeoutand interactive_timeout seems normal and I can't get some other logs about the problem.
EDIT: I find this problem only occures when I connect the server via remote clients. The local client doesn't have the problem.

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?

MySQL - High Connections

I run this command:
mysql> show status like '%onn%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| Aborted_connects | 0 |
| Connections | 37226 |
| Max_used_connections | 45 |
| Ssl_client_connects | 0 |
| Ssl_connect_renegotiates | 0 |
| Ssl_finished_connects | 0 |
| Threads_connected | 4 |
+--------------------------+-------+
I know I don't have a high traffic site, so the Connections number is confusing me.
I'm positive I close all my connections when I use PHP.
Are there other reasons why Connections keep growing?
As documented here:
Connections
The number of connection attempts (successful or not) to the MySQL
server.
It is not the number of simultaneous connections, but a cumulative number.
You can Run Below command to know Traffic on your server.
Show global status like '%Thread%';