Earlier this week, MySQL Shell 1.08 has been released. This is the first Release Candidate of this major piece of MySQL InnoDB Cluster.
Some commands have been changed and some new ones were added.
For example the following useful commands were added:
So let’s have a look on how to use the new MySQL Shell to create a MySQL InnoDB Cluster.
We have 3 blank Linux servers: mysql1, mysql2 and mysql3 all running rpm based Linux version 7 (Oracle Linux 7, CentOS 7, …).
We will install the required MySQL yum repositories and install the needed packages
We will use MySQL Shell to setup our MySQL InnoDB Cluster.
To be able to install our cluster, we will first install the repository from the MySQL release package. For more information related to MySQL’s installation or if you are using another OS, please check our online documentation.
On all 3 servers, we do:
# rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm # yum install -y mysql-community-server
The commands above, will install the MySQL Community yum repositories and install MySQL Community Server 5.7.17, being the latest GA version at the date of this post.
Now we will have to install the Shell. As this tool is not yet GA, we need to use another repository that has been installed but not enabled: mysql-tool-preview
# yum install -y mysql-shell --enablerepo=mysql-tools-preview
We are done with the installation. Now let’s initialize MySQL and start it.
Before being able to start MySQL, we need to create all necessary folders and system tables. This process is called MySQL Initialization. Let’s proceed without generating a temporary root password as it will be easier and faster for the demonstration. However, I highly recommend you to use a strong root password.
When the initialization is done, we can start MySQL. So on all the future nodes, you can proceeds like this:
# mysqld --initialize-insecure -u mysql --datadir /var/lib/mysql/ # systemctl start mysqld # systemctl status mysqld
We have now everything we need to start working in the MySQL Shell to configure all the members of our InnoDB Cluster.
First, we will check the configuration of one of our MySQL server. Some changes are required, we will perform them using the Shell and we will restart mysqld:
# mysqlsh mysql-js> dba.checkInstanceConfiguration('root@localhost:3306') ... mysql-js> dba.configureLocalInstance() ... here please create a dedicated user and password to admin the cluster (option 2) ... mysql-js> \q # systemctl restart mysqld
Now MySQL has all the required mandatory settings to run Group Replication. We can verify the configuration again in the Shell with
We have now to proceed the same way on all the other nodes, please use the same credentials when you create the user to manage your cluster, I used ‘fred@%’ as example. As you can’t configure remotely a MySQL Server, you will have to run the Shell locally on every node to be able to run
dba.configureLocalInstance() and restart mysqld.
Now that all the nodes have been restarted with the correct configuration, we can create the cluster. On one of the instances, we will connect and create the cluster using again the Shell, I did it on mysql1 and I used its ip as it’s name resolves also on the loopback interface:
# mysqlsh mysql-js> var firstname.lastname@example.org:3306' mysql-js> var i2='fred@mysql2:3306' mysql-js> var i3='fred@mysql3:3306' mysql-js> shell.connect(i1) mysql-js> var cluster=dba.createCluster('mycluster') mysql-js> cluster.status() ...
We can now validate that the dataset on the other instances is correct (no extra transactions executed). This is done by validating the GTIDs. This can be done remotely, so I will still use the MySQL Shell session I’ve open on mysql1:
mysql-js> cluster.checkInstanceState(i2) mysql-js> cluster.checkInstanceState(i3)
When the validation is passed successfully, it’s time to add the two other nodes to our cluster:
mysql-js> cluster.addInstance(i2) mysql-js> cluster.addInstance(i3) mysql-js> cluster.status()
Perfect ! We used MySQL Shell to create this MySQL InnoDB Cluster.
Now let’s see this on video with all the output of the commands:
In the next post, I will show you how to use the Shell to automate the creation of a MySQL InnoDB Cluster using Puppet.