SQL Tutorial

4 / 68

Assessment Question - Connecting to MySQL

Now, this is time for a little bit deeper hands on.

Let's try to connect to MySQL database and perform few basic actions.

What we are going to do:

Connect to MySQL

Switch to a particular database

Create a table t_test with single column "name" of type varchar 10.

Insert a row in the table with "name" as "John".

Select the data from table t_test to see the data that was inserted.

INSTRUCTIONS

From Lab -> Services, get your userid, password and hostname for MySQL.

Open a new terminal from the lab.

Submit below command after putting in correct values:

mysql -h cxln2.c.thelab-240901.internal -u sqoopuser -pNHkkP876rp

You will get connected to MySQL prompt. MySQL database system has many databases and we will switch to a particular database to perform our activities.

On the MySQL prompt, run below SQL commands:

# Switch to a database

use retail_db;

# Create the table, ignore the errors if table is already created

create table t_test(name varchar(10));

# Delete any existing rows

delete from t_test;

# Insert new rows

insert into t_test values("John");

# Select the data

select * from t_test;

You just created a table, deleted the data, inserted the data into the table and selected the data from the table. Awesome!



Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...