At times, you may want to restrict the number of connections made from a user to the database. This may be necessary to improve performance, reporting, etc.
MySQL supports this with the help MAX_USER_CONNECTIONS arrtibute associated with CREATE USER and ALTER USER statements.
User creation query:
CREATE USER 'root_user' IDENTIFIED BY 'root_user' WITH MAX_USER_CONNECTIONS 2;
Here, we have used MAX_USER_CONNECTIONS with a value of 2 along with the CREATE USER query. This ensures that there can be a max of only 2 connections allowed at any given point. This can also be a security feature when used appropriately.
In case you have a user already created, and you want to add this property, you can still do it using the ALTER USER command.
Please note that the syntax is combined along with the CREATE or ALTER USER queries.