If the mysql server, the webserver (Apache or Nginx) and the PHP interpreter (modphp, mod_fcgid.php-fpm) are on the same machine, unfortunately everyone there is competing for resources.
There are patch measures you can take (for example the use of a file descriptor cache, an in-memory cache such as varnish), the use of well-tuned OpCaché in PHP and the MySQL query cache.
Anyway, if the saturation of the communication is with MySQL and it is not that the machine itself stays stuck, it makes me think that it is not a memory issue (if it really hits the memory, it would collapse everything and you could see it in the syslog) but to the handling of the file descriptors.
By using socket connection you are gaining a better performance than the TCP / IP connection, but you go through the file system, which has two possible weaknesses: that the disk be filled or that the system you can not handle more file descriptors (this includes connection sockets and open tables at a given time). If it came first, the error could manifest itself in other ways than being consistently reported by MySQL, but it could also be that the mysql process is creating and closing sockets more frequently than other processes.
You can limit the number of files that MySQL will keep open by using the parameters open_files_limit and table_open_cache . If the problem were by the amount of file descriptors, this path would allow to sacrifice performance by simultaneity.
Leaving the above aside
500 concurrent users is not necessarily much. In a forum that used to be very successful, it handled 3000 simultaneous users at rush hour and the machine had exactly 8GB (although they were 4 CPUs but never exceeded 10% load). And looking at the ways to optimize the performance of the site (which at that time was mediocre) I realized that it was not a problem of MySQL resources but the forum engine (VBulletin 3.6) made many very inefficient queries to deploy a conversation thread In particular, many of the installed plugins had the worst queries.
In wordpress, the cover of the site, something similar happened. Many inefficient queries and most of them blame plugins.
Find a way to isolate the heaviest queries on your site. You may be able to mitigate the problem by creating indexes that accelerate such queries. Also consider the possibility of disabling certain plugins when the site is under heavy load.
Finally, if you use Cloudflare as a DNS provider, you can transfer some of the load to your CDN, and tune the cache settings to make it more aggressive.