Too many connections error in MariaDB implies that all available connections are in use by other clients. Here are few methods to resolve this error:
1. Increase the maximum number of connections:
You can increase the number of allowed connections for MariaDB. Use the following command to edit MariaDB’s configuration file.
```
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
```
Search for the [mysqld] section in the file and add the following line:
```
max_connections = 200
```
The number 200 is just an example. Set the appropriate number of connections according to your requirements.
After adding the line, save the file and exit the editor. Then, you need to restart MariaDB to apply the changes:
```
sudo systemctl restart mariadb
```
2. Optimize your queries and applications:
Too many connections could be due to poorly optimized applications or queries that take a long time to execute, thus holding up a connection. Check your application for any slow queries and optimize them.
3. Monitor your applications:
Monitor your application to see how many connections it is opening, how long the connections are open for, and what the queries are doing. There are different tools available to monitor MariaDB like MONyog, MariaDB Monitor, etc.
4. Use Connection Pooling:
If you are running a dynamic website that is running on a web programming language like PHP, then every page request to your web server is most likely opening a new MariaDB connection. In this case, you might want to consider setting up a connection pool, which will reuse a small number of persistent connections, rather than creating a new connection every time a page is loaded.