Seting Up Mysql

This section will demonstrate to create a MYSQL database using the template.

Create Mysql

Click on Add to Project button and you will be taken to select an image or template. You will see the application create screen as shown below:

application_create_screen

Scroll down and click on Data Stores session. Find MySQL (Ephemeral) template from the list and click Select. You will also notice MySQL (Persistent) template. But we will address that in a different lab exercise.

mysql_ephemeral_template

You will be taken to the mysql ephemeral creation screen. Click edit parameters and edit the values to use the following values:

Database Service Name: mysql
MySQL Connection Username: test_user
MySQL Connection Password: test_pass
MySQL Database Name: sample

Click the Create button.

mysql_ephemeral_creation

Click Go to overview.

Explosing the Web Console

This secion will demonstrate using web console to configure the mysql.

  1. Click onto mysql deployments config

  2. Click on the Actions button and select Edit Health Checks

  3. Under the Readiness Probe section remove the single quotes around $MYSQL_PASSWORD

  4. Click Save

  5. Click Applications and select Pods

  6. Click onto the pod name

  7. Click on the Actions button and select Delete

Browse over to Pods, Services and Deployments from the Applications tab to notice the additions to the project. You will note that the service has been assigned an IP address that starts with 172.*. Make a note of that. Also note the port that is exposed by this service. By default it exposes 3306.

Add data to MySQL database

List all runing pods, you will find one pod for mysql

$ oc get pod
NAME            READY     STATUS    RESTARTS   AGE
mysql-1-g22vt   1/1       Running   0          3m

Enter the pod by running the following command. Substitute the pod name with your mysql pod name.

$ oc rsh mysql-1-g22vt
sh-4.2$

You will be taken to a bash prompt inside the running pod. Now using the service ip address you noted earlier, port number, username and password you used start the mysql client as shown below. You will have to substitute your values here.

sh-4.2$ mysql -u test_user -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 89
Server version: 5.7.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

You will be taken to the mysql prompt. See the list of databases. You will notice that the sample database that you requested is added and available.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| sample             |
+--------------------+
2 rows in set (0.00 sec)

Change over to use the sample database

mysql> use sample;
Database changed

Now show tables shows an empty set. So let us create a table and add some records using the commands shown below.

Create Table
CREATE TABLE PRODUCT (ID integer, SYMBOL varchar(16), COMPANY_NAME varchar(256), CONSTRAINT PRODUCT_PK PRIMARY KEY(ID));
Add some data
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1001,'RHT','Red Hat Corporation');
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1007,'IBM','International Business Machines Corporation');
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1008,'DELL','Dell Computer Corporation');
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1010,'HPQ','Hewlett-Packard Company');
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1033,'FCZ','Ford Motor Credit Company');
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1034,'SAP','SAP AG');
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1036,'TM','Toyota Motor Corporation');
Verify that the records
SELECT * FROM PRODUCT;

results matching ""

    No results matching ""