Skip to content

MySQL Workbench is a unified visual tool for database architects, developers, and DBAs. It provides data modeling, SQL development, and comprehensive administration tools. This guide focuses on how to keep the connection alive in MySQL Workbench, ensuring uninterrupted work sessions and avoiding the hassle of frequent reconnections.

Understanding Connection Timeouts

Connection timeouts in MySQL Workbench occur when the server closes an idle connection after a certain period. This can interrupt workflows and require frequent reconnections, which can be frustrating.

Configuring Server Settings

  1. Edit the MySQL Configuration File: Locate and open the my.cnf (Linux) or my.ini (Windows) file in a text editor. This file is typically found in the MySQL installation directory.

    [mysqld]
    wait_timeout = 28800
    interactive_timeout = 28800
    
    • wait_timeout: The number of seconds the server waits for activity on a non-interactive connection before closing it.
    • interactive_timeout: Similar to wait_timeout, but for interactive connections like those used by MySQL Workbench.
  2. Restart MySQL Service: After editing, restart the MySQL service to apply the changes.

    sudo service mysql restart
    

Adjusting Workbench Preferences

  1. Open MySQL Workbench Preferences: Launch MySQL Workbench, and navigate to Edit > Preferences (Linux/Windows) or MySQL Workbench > Preferences (macOS).

  2. Configure SQL Editor Settings:

    • Navigate to the SQL Editor section.
    • Locate the option DBMS connection keep-alive interval (in seconds).
    • Set a suitable value (e.g., 600 for 10 minutes).
    -- Example of a simple query to keep the connection alive
    SELECT 1;
    
    • This setting sends a simple query to the server at specified intervals to keep the connection active.

Utilizing Scripts

  • Write a Keep-Alive Script: Create a small SQL script with a simple query (like SELECT 1;) and schedule it to run at regular intervals.

    SELECT 1;
    
    • This approach is similar to setting the keep-alive interval but offers more control over the query and timing.

Leveraging External Tools

If MySQL Workbench settings alone are not sufficient, consider using external tools or scripts that periodically interact with the database to prevent timeouts.

Third-Party Tools

  • Use External Keep-Alive Tools: Some third-party tools can send queries to your MySQL server at regular intervals to keep connections alive.

Automation Scripts

  • Automate Connection Refreshes: Write a simple script in your preferred programming language to connect to the database and execute a query periodically.

Conclusion

Keeping your MySQL Workbench connection alive is essential for a smooth and uninterrupted workflow. By configuring server and Workbench settings, and optionally using external tools or scripts, you can prevent frequent disconnections due to timeouts. Remember, the key is to balance between server performance and the convenience of a persistent connection.

Written by

Robert Cooper avatar

Robert Cooper

Senior Engineer at Basedash

Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.

View full author profile →

Looking for an AI-native BI tool?

Basedash lets you build charts, dashboards, and reports in seconds using all your data.