--查看當前max_user_connections連接參數值為0,表示沒有限制.
mysql> show global variables like '%connect%'; +--------------------------+-----------------+ | Variable_name | Value | +--------------------------+-----------------+ | character_set_connection | utf8 | | collation_connection | utf8_general_ci | | connect_timeout | 10 | | init_connect | | | max_connect_errors | 10 | | max_connections | 160 | | max_user_connections | 0 | +--------------------------+-----------------+ 7 rows in set (0.00 sec) --設置max_user_connections值為2 mysql> set global max_user_connections=2; Query OK, 0 rows affected (0.00 sec) --查看設置是否生效 mysql> show global variables like '%connect%'; +--------------------------+-----------------+ | Variable_name | Value | +--------------------------+-----------------+ | character_set_connection | utf8 | | collation_connection | utf8_general_ci | | connect_timeout | 10 | | init_connect | | | max_connect_errors | 10 | | max_connections | 160 | | max_user_connections | 2 | +--------------------------+-----------------+ 7 rows in set (0.00 sec) --退出數據庫 mysql> exit Bye --登錄數據庫 C:\Users\ArcerZhang>mysql -uroot -parcerzhang Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.5.28 MySQL Community Server (GPL) Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. --查看數據庫 mysql> show global variables like '%connect%'; +--------------------------+-----------------+ | Variable_name | Value | +--------------------------+-----------------+ | character_set_connection | utf8 | | collation_connection | utf8_general_ci | | connect_timeout | 10 | | init_connect | | | max_connect_errors | 10 | | max_connections | 160 | | max_user_connections | 2 | +--------------------------+-----------------+ 7 rows in set (0.00 sec) mysql>
二、登錄第一個窗口
C:\Users\ArcerZhang>mysql -uroot -parcerzhang Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.5.28 MySQL Community Server (GPL) Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
三、登錄第二個窗口
C:\Users\ArcerZhang>mysql -uroot -parcerzhang ERROR 1203 (42000): User root already has more than 'max_user_connections' active connections C:\Users\ArcerZhang>
四、結論
當max_user_connections設置為2時,使用一個用戶登錄mysql server,當開啟第二窗口登錄時,就會報錯了.而且第一個試驗窗口也算是一個用戶登錄.