Database Service Name: mysql MySQL Connection Username: test_user MySQL Connection Password: test_pass MySQL Database Name: sample
Seting Up Mysql
This section will demonstrate to create a MYSQL database using the template.
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:
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.
You will be taken to the mysql ephemeral creation screen. Click edit parameters and edit the values to use the following values:
Click the Create button.
Click Go to overview.
Explosing the Web Console
This secion will demonstrate using web console to configure the mysql.
Click on the Actions button and select Edit Health Checks
Under the Readiness Probe section remove the single quotes around $MYSQL_PASSWORD
Click Applications and select Pods
Click onto the pod name
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
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
mysql> use sample; Database changed
show tables shows an empty set. So let us create a table and add some records using the commands shown below.
CREATE TABLE PRODUCT (ID integer, SYMBOL varchar(16), COMPANY_NAME varchar(256), CONSTRAINT PRODUCT_PK PRIMARY KEY(ID));
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');
SELECT * FROM PRODUCT;