-
Notifications
You must be signed in to change notification settings - Fork 120
MySQL Performance Optimization Guide
This guide helps system administrators optimize MySQL database performance to improve HMIS application speed, especially for pharmacy module operations like autocomplete searches and stock management.
Apply these optimizations if you experience:
- Slow autocomplete dropdowns in pharmacy sales
- Long loading times when selecting items or stock
- General application slowness during peak usage
- Database timeouts or connection issues
- Administrative access to the MySQL server
- Ability to restart MySQL service
- At least 1GB of available RAM on the server
- Database backup completed (recommended)
-
Check available memory:
free -h
You need at least 2GB total RAM for optimal performance.
-
Check current MySQL configuration:
mysql -u root -p -e "SHOW VARIABLES LIKE 'innodb_buffer_pool_size';" -
Verify MySQL version:
mysql -u root -p -e "SELECT VERSION();"
The HMIS system includes automatic database migration for performance indexes.
-
Access the Migration Page:
- Navigate to:
http://your-server:8080/hmis/faces/admin/database_migration.xhtml - Login with administrator credentials
- Navigate to:
-
Execute Migration v2.1.11:
- Look for "Performance optimization indexes" migration
- Click "Execute All Pending Migrations"
- Wait for completion (approximately 5-15 minutes)
-
Verify Success:
- Check that migration status shows "Executed"
- No errors in the execution log
- 50-80% faster autocomplete searches
- Improved stock filtering performance
- Better overall pharmacy module responsiveness
sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf.backup.$(date +%Y%m%d)Choose your server type and apply the corresponding configuration:
# Add to /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
# Memory optimization
innodb_buffer_pool_size = 1024M
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 2
# Connection optimization
max_connections = 100
query_cache_size = 64M# Add to /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
# Memory optimization
innodb_buffer_pool_size = 2048M
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 2
# Connection optimization
max_connections = 150
query_cache_size = 128M# Add to /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
# Memory optimization
innodb_buffer_pool_size = 4096M
innodb_log_file_size = 512M
innodb_flush_log_at_trx_commit = 2
# Connection optimization
max_connections = 200
query_cache_size = 256M-
Open the configuration file:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
-
Add the appropriate settings from above at the end of the file
-
Save and exit (Ctrl+X, then Y, then Enter in nano)
sudo systemctl restart mysql
sudo systemctl status mysqlsudo systemctl restart mysqld
sudo systemctl status mysqldsudo service mysql restart
sudo service mysql statusmysql -u root -p -e "SHOW VARIABLES LIKE 'innodb_buffer_pool_size';"
mysql -u root -p -e "SHOW VARIABLES LIKE 'max_connections';"-
Access HMIS pharmacy module
-
Test autocomplete functionality:
- Go to pharmacy sales page
- Try typing in item search boxes
- Notice improved response time
-
Monitor for any issues:
- Check for connection errors
- Verify normal application functionality
Check these metrics weekly:
# Check database connections
mysql -u root -p -e "SHOW STATUS LIKE 'Threads_connected';"
# Check buffer pool efficiency
mysql -u root -p -e "SHOW ENGINE INNODB STATUS;" | grep -A 5 "BUFFER POOL"-
Check error logs:
sudo tail -f /var/log/mysql/error.log
-
Common issues and fixes:
Insufficient memory error:
- Reduce
innodb_buffer_pool_sizeto 512M - Restart MySQL service
Log file size error:
- Remove old log files:
sudo rm /var/lib/mysql/ib_logfile* - Restart MySQL service
- Reduce
-
Verify migration executed:
- Check admin migration page
- Ensure v2.1.11 shows as "Executed"
-
Check available memory:
free -h top
-
Review MySQL settings:
- Ensure configuration changes were saved
- Verify MySQL restart completed successfully
If you see "too many connections" errors:
-
Temporary fix:
mysql -u root -p -e "SET GLOBAL max_connections = 200;" -
Permanent fix:
- Increase
max_connectionsin configuration file - Restart MySQL service
- Increase
-
Optimize database tables:
mysql -u root -p -e "OPTIMIZE TABLE coop.ITEM, coop.STOCK, coop.ITEMBATCH;" -
Check disk space:
df -h
-
Review slow query log (if enabled)
- Autocomplete response time: Should be under 1 second
- Page load times: Pharmacy pages should load within 3-5 seconds
- Database connections: Should stay under 80% of maximum
- Memory usage: MySQL should use allocated buffer pool efficiently
After completing all optimizations:
- Autocomplete searches: 50-80% faster response time
- Stock filtering: 60-90% performance improvement
- Page loading: 25-50% faster overall
- User experience: Significantly more responsive interface
For additional technical details, refer to:
- Developer documentation in
developer_docs/database/mysql-performance-configuration.md - MySQL official documentation for your version
- Contact development team for complex issues
- Always backup your database before making configuration changes
- Test configuration changes during low-usage periods
- Monitor system performance after changes
- Keep backup copies of working configurations
- Document any custom modifications for future reference