[关闭]
@llplmlyd 2023-05-25T16:17:44.000000Z 字数 6429 阅读 397

What is the purpose of “system user” in MySQL Replication

数据库


refer to https://www.thegeekdiary.com/what-is-the-purpose-of-system-user-in-mysql-replication/

This post focusses on understanding why the “system user” is seen in SHOW PROCESSLIST and the information_schema.PROCESSLIST view on replication slaves.

The system user is not a real user and is used for display purposes only to indicate it is the system performing the task. It is used by the I/O and SQL threads (connection and applier threads) on a replication slave. These threads are handled by the system and not by a login user.

The system user can for example be seen in the output of SHOW PROCESSLIST or the information_schema.PROCESSLIST view:

  1. mysql> SHOW PROCESSLIST;
  2. +----+-----------------+-----------------+--------------------+---------+-------+--------------------------------------------------------+------------------+
  3. | Id | User | Host | db | Command | Time | State | Info |
  4. +----+-----------------+-----------------+--------------------+---------+-------+--------------------------------------------------------+------------------+
  5. | 2 | system user | | NULL | Connect | 10103 | Waiting for master to send event | NULL |
  6. | 3 | event_scheduler | localhost | NULL | Daemon | 10102 | Waiting on empty queue | NULL |
  7. | 8 | root | localhost:33356 | performance_schema | Query | 0 | starting | SHOW PROCESSLIST |
  8. | 10 | system user | | NULL | Connect | 0 | Slave has read all relay log; waiting for more updates | NULL |
  9. | 11 | system user | | NULL | Connect | 0 | System lock | NULL |
  10. | 12 | system user | | NULL | Connect | 0 | System lock | NULL |
  11. | 13 | system user | | NULL | Connect | 0 | System lock | NULL |
  12. | 14 | system user | | NULL | Connect | 0 | System lock | NULL |
  13. | 15 | system user | | NULL | Connect | 0 | Waiting for an event from Coordinator | NULL |
  14. | 16 | system user | | NULL | Connect | 0 | Waiting for an event from Coordinator | NULL |
  15. | 17 | system user | | NULL | Connect | 0 | Waiting for an event from Coordinator | NULL |
  16. | 18 | system user | | NULL | Connect | 0 | Waiting for an event from Coordinator | NULL |
  17. +----+-----------------+-----------------+--------------------+---------+-------+--------------------------------------------------------+------------------+
  18. 12 rows in set (0.00 sec)
  19. mysql> SELECT * FROM information_schema.PROCESSLIST;
  20. +----+-----------------+-----------------+--------------------+---------+-------+---------------------------------------------+----------------------------------------------+
  21. | ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO |
  22. +----+-----------------+-----------------+--------------------+---------+-------+---------------------------------------------+----------------------------------------------+
  23. | 3 | event_scheduler | localhost | NULL | Daemon | 10173 | Waiting on empty queue | NULL |
  24. | 12 | system user | | NULL | Connect | 3 | System lock | NULL |
  25. | 14 | system user | | NULL | Connect | 3 | Waiting for an event from Coordinator | NULL |
  26. | 13 | system user | | NULL | Connect | 3 | System lock | NULL |
  27. | 2 | system user | | NULL | Connect | 10174 | Waiting for master to send event | NULL |
  28. | 8 | root | localhost:33356 | performance_schema | Query | 0 | executing | SELECT * FROM information_schema.processlist |
  29. | 16 | system user | | NULL | Connect | 3 | Waiting for an event from Coordinator | NULL |
  30. | 15 | system user | | NULL | Connect | 3 | Waiting for an event from Coordinator | NULL |
  31. | 17 | system user | | NULL | Connect | 3 | Waiting for an event from Coordinator | NULL |
  32. | 18 | system user | | NULL | Connect | 3 | Waiting for an event from Coordinator | NULL |
  33. | 10 | system user | | NULL | Connect | 0 | Waiting for dependent transaction to commit | NULL |
  34. | 11 | system user | | NULL | Connect | 3 | Waiting for an event from Coordinator | NULL |
  35. +----+-----------------+-----------------+--------------------+---------+-------+---------------------------------------------+----------------------------------------------+
  36. 12 rows in set (0.00 sec)

The Performance Schema will not display “system user” but rather root@localhost for these connections. The sys schema will display the thread name instead. For example using the performance_schema.threads table and sys.session view:

  1. mysql> SELECT THREAD_ID, NAME, PROCESSLIST_ID, PROCESSLIST_USER, PROCESSLIST_HOST, PROCESSLIST_TIME, PROCESSLIST_STATE FROM performance_schema.threads WHERE TYPE = 'foreground';
  2. +-----------+--------------------------------------+----------------+------------------+------------------+------------------+--------------------------------------------------------+
  3. | THREAD_ID | NAME | PROCESSLIST_ID | PROCESSLIST_USER | PROCESSLIST_HOST | PROCESSLIST_TIME | PROCESSLIST_STATE |
  4. +-----------+--------------------------------------+----------------+------------------+------------------+------------------+--------------------------------------------------------+
  5. | 77 | thread/sql/slave_io | 2 | NULL | NULL | 10111 | Waiting for master to send event |
  6. | 78 | thread/sql/event_scheduler | 3 | NULL | NULL | NULL | Waiting on empty queue |
  7. | 81 | thread/sql/compress_gtid_table | 4 | NULL | NULL | 10110 | Suspending |
  8. | 83 | thread/thread_pool/tp_one_connection | 8 | root | localhost | 0 | Sending data |
  9. | 85 | thread/sql/slave_sql | 10 | root | localhost | 0 | Slave has read all relay log; waiting for more updates |
  10. | 86 | thread/sql/slave_worker | 11 | root | localhost | 0 | System lock |
  11. | 87 | thread/sql/slave_worker | 12 | root | localhost | 0 | System lock |
  12. | 88 | thread/sql/slave_worker | 13 | root | localhost | 0 | System lock |
  13. | 89 | thread/sql/slave_worker | 14 | root | localhost | 0 | Waiting for an event from Coordinator |
  14. | 90 | thread/sql/slave_worker | 15 | root | localhost | 0 | Waiting for an event from Coordinator |
  15. | 91 | thread/sql/slave_worker | 16 | root | localhost | 0 | Waiting for an event from Coordinator |
  16. | 92 | thread/sql/slave_worker | 17 | root | localhost | 0 | Waiting for an event from Coordinator |
  17. | 93 | thread/sql/slave_worker | 18 | root | localhost | 0 | Waiting for an event from Coordinator |
  18. +-----------+--------------------------------------+----------------+------------------+------------------+------------------+--------------------------------------------------------+
  19. 13 rows in set (0.00 sec)
  20. mysql> SELECT thd_id, conn_id, user, state, time FROM sys.session;
  21. +--------+---------+---------------------+---------------------------------------------+-------+
  22. | thd_id | conn_id | user | state | time |
  23. +--------+---------+---------------------+---------------------------------------------+-------+
  24. | 77 | 2 | sql/slave_io | Waiting for master to send event | 10378 |
  25. | 83 | 8 | root@localhost | Sending data | 0 |
  26. | 86 | 11 | sql/slave_worker | System lock | 0 |
  27. | 87 | 12 | sql/slave_worker | System lock | 0 |
  28. | 88 | 13 | sql/slave_worker | Waiting for an event from Coordinator | 0 |
  29. | 89 | 14 | sql/slave_worker | Waiting for an event from Coordinator | 0 |
  30. | 90 | 15 | sql/slave_worker | System lock | 0 |
  31. | 91 | 16 | sql/slave_worker | Waiting for an event from Coordinator | 0 |
  32. | 92 | 17 | sql/slave_worker | Waiting for an event from Coordinator | 0 |
  33. | 93 | 18 | sql/slave_worker | Waiting for an event from Coordinator | 0 |
  34. | 85 | 10 | sql/slave_sql | Waiting for dependent transaction to commit | 0 |
  35. | 78 | 3 | sql/event_scheduler | Waiting on empty queue | NULL |
  36. +--------+---------+---------------------+---------------------------------------------+-------+

12 rows in set (0.42 sec)
Note: It is impossible to login as the “system user” – it is strictly internal only.

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注