Test MySQL

This workshop has been deprecated and archived. The new Amazon EKS Workshop is now available at www.eksworkshop.com.

You can use mysql-client to send some data to the leader, mysql-0.mysql by running the following command.

kubectl -n mysql run mysql-client --image=mysql:5.7 -i --rm --restart=Never --\
  mysql -h mysql-0.mysql <<EOF
CREATE DATABASE test;
CREATE TABLE test.messages (message VARCHAR(250));
INSERT INTO test.messages VALUES ('hello, from mysql-client');
EOF

Run the following to test follower (mysql-read) received the data.

kubectl -n mysql run mysql-client --image=mysql:5.7 -it --rm --restart=Never --\
  mysql -h mysql-read -e "SELECT * FROM test.messages"

The output should look like this.


+--------------------------+
| message                  |
+--------------------------+
| hello, from mysql-client |
+--------------------------+

To test load balancing across followers, run the following command.

kubectl -n mysql run mysql-client-loop --image=mysql:5.7 -i -t --rm --restart=Never --\
   bash -ic "while sleep 1; do mysql -h mysql-read -e 'SELECT @@server_id,NOW()'; done"

Each MySQL instance is assigned a unique identifier, and it can be retrieved using @@server_id. It will print the server id serving the request and the timestamp.


+-------------+---------------------+
| @@server_id | NOW()               |
+-------------+---------------------+
|         101 | 2021-02-21 19:17:52 |
+-------------+---------------------+
+-------------+---------------------+
| @@server_id | NOW()               |
+-------------+---------------------+
|         101 | 2021-02-21 19:17:53 |
+-------------+---------------------+
+-------------+---------------------+
| @@server_id | NOW()               |
+-------------+---------------------+
|         100 | 2021-02-21 19:17:54 |
+-------------+---------------------+
+-------------+---------------------+
| @@server_id | NOW()               |
+-------------+---------------------+
|         100 | 2021-02-21 19:17:55 |
+-------------+---------------------+

Leave this open in a separate window while you test failure in the next section.