Step-by-Step Guide to Setting Up MySQL InnoDB Cluster



You set up a MySQL InnoDB Cluster by doing simple steps. This guide shows you how to build a strong database system. It keeps your data safe and easy to get, even if a server stops working. High availability and fault tolerance help your apps stay online. You learn ways to make your database tough and trustworthy by using tested methods.
Make sure your servers meet the needed requirements. Use three servers with the same hardware. This helps set up MySQL InnoDB Cluster easily.
Put the newest MySQL Server and MySQL Shell on each node. Using the same software versions stops problems with compatibility.
Keep your MySQL safe by using strong passwords. Turn off features you do not need. This keeps your data safe from people who should not see it.
Use MySQL Router to handle app connections. It helps balance the load. It also keeps things working if one node stops.
Check your cluster’s health often and make backups. This keeps your data safe. It helps you fix problems fast if they happen.
You must check your setup before you build a MySQL InnoDB Cluster. Getting ready helps you stop problems and makes things easier.
You need three servers for a basic cluster. These can be real or virtual. Each server needs:
2 CPU cores or more
At least 4 GB RAM
20 GB of free space
64-bit Linux like Ubuntu 20.04 or CentOS 8
Tip: Use the same hardware for every node. This helps keep your cluster running smoothly.
A good network is important for high availability. Put your servers on the same network or cloud subnet. Give each server a static IP address. Make sure all servers talk to each other on these ports:
| Service | Port |
|---|---|
| MySQL Server | 3306 |
| Group Replication | 33061 |
| MySQL Shell | 22 (SSH) |
Turn off firewalls or open these ports. This lets your servers connect. Use hostnames or IPs that do not change.
Put the newest versions of these tools on every server:
MySQL Server (8.0 or higher)
MySQL Shell
MySQL Router
Get them from the official MySQL website. Make sure your system is updated. You need sudo or root access to set up and change software.
Note: MySQL InnoDB Cluster works best if all nodes use the same MySQL version.
After you finish these steps, you can start installing. Good preparation helps your MySQL InnoDB Cluster stay safe and strong.
Setting up your servers with the right software is the next step. You need to install MySQL Server and MySQL Shell on each node. Follow these steps to make sure your MySQL InnoDB Cluster works well.
Start by installing MySQL Server on all three nodes. Use your system’s package manager for a smooth process. For Ubuntu, run:
| |
For CentOS, use:
| |
After installation, check the MySQL service:
| |
You should see that MySQL is active and running. If not, start it with:
| |
Tip: Always install the same MySQL version on every node. This helps avoid compatibility issues.
MySQL Shell gives you powerful tools to manage your cluster. Install it on each server. On Ubuntu, type:
| |
On CentOS, use:
| |
Check the installation by running:
| |
You should see the version number. If you do, you are ready for the next step.
Secure your MySQL installation. Run the security script:
| |
Set a strong root password. Remove anonymous users. Disallow remote root login. Remove the test database. Answer each prompt to make your server safer.
Next, enable binary logging and set the server ID. Edit the MySQL configuration file (/etc/mysql/my.cnf or /etc/my.cnf). Add these lines under the [mysqld] section:
| |
Change the server-id for each node (use 1, 2, and 3). Save the file and restart MySQL:
| |
You have now installed and configured the software needed for your MySQL InnoDB Cluster.
You must prepare each server before you add it to your MySQL InnoDB Cluster. This step helps you avoid common problems and ensures smooth operation.
Map all hostnames and IP addresses in the /etc/hosts file on every server. This step ensures that each node can find the others by name.
Stop and disable AppArmor. AppArmor can block MySQL processes and cause issues with replication.
Download and install the latest MySQL APT configuration repository. This keeps your MySQL packages up to date.
Install the GPG key to verify package downloads.
Update your package list so your system sees the newest MySQL versions.
Install MySQL Server and MySQL Shell if you have not done so already.
Set a strong root password during installation. This protects your database from unauthorized access.
Choose the legacy authentication method for compatibility with older clients.
Use MySQL Shell to configure the server for Group Replication. This step is vital for cluster communication.
Create a new admin account for the cluster. Give it only the permissions it needs.
Tip: Use the same steps on every node. Consistency helps prevent errors later.
You can use sandbox instances for testing your cluster setup before you go live. MySQL Shell makes this process easy.
To create sandbox instances, run the following command on your management server:
| |
This command sets up isolated MySQL instances on your local machine. You can use these for practice or to test your configuration before you use real servers.
Note: Sandboxes are for testing only. Do not use them in production.
Now you can start building your MySQL InnoDB Cluster. Open MySQL Shell and connect to the first node as the root user:
| |
Switch to JavaScript mode by typing:
| |
Create the cluster with:
| |
This command sets up the cluster on your first node. MySQL Shell checks your configuration and enables Group Replication.
Tip: Use a clear name for your cluster. This helps you manage it later.
After you create the cluster, you need to add the other two nodes. Stay in MySQL Shell and run:
| |
Replace <second-node-ip> and <third-node-ip> with the actual IP addresses of your other servers.
MySQL Shell will check each node and join it to the cluster. You now have a three-node setup, which gives you high availability and fault tolerance.
Callout: A three-node MySQL InnoDB Cluster can keep running even if one node fails. This setup protects your data and keeps your applications online.
You should always check the health of your cluster after setup. In MySQL Shell, run:
| |
You will see a summary of your cluster. Look for all nodes listed as ONLINE. If you see errors, review your configuration and repeat the steps as needed.
A healthy MySQL InnoDB Cluster gives you a strong foundation for your database. You can now move on to deploying MySQL Router and connecting your applications.
Setting up MySQL Router helps your apps talk to your MySQL InnoDB Cluster. MySQL Router sends traffic to the right place. It keeps your database working, even if one node stops. You can follow these steps to put in and set up MySQL Router for your cluster.
Put MySQL Router on a server that can reach all cluster nodes. Most people install it on the same server as their app. To install MySQL Router on Linux, do these steps:
| |
| |
| |
| |
| |
| |
Tip: Always use the newest MySQL Router. This helps keep your cluster safe and working well.
After you install MySQL Router, you need to set it up for your MySQL InnoDB Cluster. Bootstrapping gets the router ready to send traffic to the right nodes. Run this command:
| |
Change <primary-node-ip> to your cluster’s main node IP. This command makes config files and system accounts for the router.
MySQL Router has features that help your cluster work better:
| Feature | Description |
|---|---|
| Read/Write Splitting | Sends writes to the main node and reads to other nodes. |
| Load Balancing | Shares traffic across all nodes. |
| Automatic Topology Detection | Finds cluster nodes and sets itself up. |
| Failure Handling | Sees when nodes fail and sends traffic to good nodes. |
Note: These features help your apps stay online and keep your data safe.
Now you can make your apps use MySQL Router instead of talking to cluster nodes directly. Use the ports MySQL Router gives for reading and writing. This setup lets your apps use high availability and load balancing without big changes.
Look at your app’s database settings. Change the host and port to match MySQL Router. Test the connection to see if it works.
🛡️ MySQL Router keeps your data safe and your apps running, even if a cluster node goes down.
You can make your cluster bigger or smaller by adding or removing nodes. This helps you handle more users or save resources. Use MySQL Shell to do this. The table below shows the main commands you need:
| Action | Command |
|---|---|
| Add a Node | cluster.addInstance(“db3:3306”) |
| Verify Addition | cluster.status() or cluster.describe() |
| Remove a Node | cluster.removeInstance(“db3:3306”) |
| Verify Removal | cluster.status() or cluster.describe() |
Always check the cluster status after you make changes. This makes sure your cluster is working right.
Watching your cluster helps keep it working well. You can use different tools to check health and speed:
New Relic shows how your cluster is doing and finds problems.
Sematext gives you charts and tracks what happens in your cluster.
Percona Monitoring and Management Tool lets you see what is happening right now and checks your queries.
Dynatrace helps you see everything and gives you details.
Pick the tool that works best for you. Checking your cluster often helps you find problems early.
Keeping your data safe is very important. You should back up your database often and know how to get it back. The table below shows ways to back up and what is best:
| Consideration | Backup Method Type | Recommendation |
|---|---|---|
| Database size and growth | Logical backups (mysqldump) vs. Physical backups | Use logical backups for small databases; physical for large datasets. |
| Recovery time objectives (RTO) | Physical backups vs. Logical backups | Choose physical backups for fast recovery. |
| Recovery point objectives (RPO) | Full with incremental backups vs. Replication | Combine full and incremental backups for less data loss. |
| System availability requirements | Hot backups vs. Cold backups | Use hot backups for high-availability systems. |
| Storage and cost constraints | Logical vs. Physical backups | Logical backups cost less; physical backups for critical apps. |
| Technical complexity and expertise | User-friendly vs. Advanced solutions | Use simple tools for basic setups; advanced for complex needs. |
| Disaster recovery needs | Local vs. Remote/cloud backups | Combine local and remote backups for better recovery. |
| Regulatory compliance | Encryption and secure transfers | Use tools with compliance features. |
| Frequency of data changes | Incremental vs. Periodic full backups | Use incremental for dynamic data; periodic for static. |
Make a backup plan that fits your system and your business.
Keeping your cluster safe protects your data and users. Follow these tips:
Make strong rules for user accounts.
Use roles to control what people can do.
Make sure passwords are strong.
Turn off things you do not use.
Use encryption to keep data safe when stored or sent.
Always watch and check what is happening.
Teach users how to stay safe. This helps stop mistakes and makes passwords better. It also helps people pay attention to security. You should also make a plan for what to do if something bad happens. Write down steps for finding, stopping, fixing, and recovering from problems. This helps you act fast if there is a security issue.
A well-cared-for MySQL InnoDB Cluster helps your business. It gives you high availability, strong security, and keeps your data safe.
You now know how to set up MySQL InnoDB Cluster. This cluster keeps your data safe and helps your apps stay online. If something fails, your apps can recover quickly. You can make your setup better by doing these things:
Add more nodes to make your cluster stronger.
Change server settings to help it run faster.
Look at advanced features for bigger companies.
| Feature | Benefit |
|---|---|
| Replication control | You can manage and promote replicas easily. |
| Monitoring | You can watch health and performance right away. |
Keep trying new tools and features to make your cluster work even better.
First, restart the failed node. Then, use MySQL Shell to rejoin it. Run cluster.rejoinInstance('root@<node-ip>') to add it back. Always check the cluster status after you finish.
Yes, you can upgrade nodes one by one. Rolling upgrades keep your cluster working. Always test upgrades in a sandbox before you update real servers.
You need three nodes for high availability. This setup lets your cluster keep working if one node fails.
Use tools like MySQL Shell, Percona Monitoring, or New Relic. Run cluster.status() in MySQL Shell to check node status and replication health.
You should use MySQL Router for connections. It manages traffic, balances loads, and handles failover. Direct connections can cause downtime if a node fails.
SQLFlash is your AI-powered SQL Optimization Partner.
Based on AI models, we accurately identify SQL performance bottlenecks and optimize query performance, freeing you from the cumbersome SQL tuning process so you can fully focus on developing and implementing business logic.
Join us and experience the power of SQLFlash today!.