Creating a Database and Table in MySQL

1 hour
  • 5 Learning Objectives

About this Hands-on Lab

Working with databases and tables is a foundational skill for any database administrator. This ability to create multiple databases and multiple tables within each database allows administrators to ensure that data is grouped in a logical order. In this lab, you will walk through creating and deleting databases and tables in a MySQL server.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Log into the MySQL Database

As the cloud_user, run the following command and enter the password from the instructions (under Additonal Information) when prompted:

# mysql -u root -p

Delete the `bad_data` Database from the MySQL Server

In the mysql prompt, run the following command:

mysql> DROP DATABASE bad_data;

Create a Database Named `customer_info`

In the mysql prompt, run the following command:

mysql> CREATE DATABASE customer_info;

Delete the Table `payment_info` from the `2004_data` Database

In the mysql prompt, change the database to 2004_data:

mysql> USE 2004_data;

Drop the payment_info table:

mysql> DROP TABLE payment_info;

Create a Table Named `payment_info` in the `customer_info` Database According to the Characteristics Provided in the Instructions

Change the database to customer_info:

mysql> USE customer_info;

Create the payment_info table with the characteristics provided:

mysql> CREATE TABLE payment_info (cust_id INT AUTO_INCREMENT PRIMARY KEY, user_name VARCHAR(50) UNIQUE, card_number INT, purchase_item VARCHAR(255));

Verify that the table was created as expected:

mysql> DESCRIBE payment_info;

Exit the mysql prompt:

mysql> exit

Additional Resources

Your team of database administrators have been asked to clean up some out of date information on the server and to prepare for the upcoming sales year. To accomplish this you will need to delete the bad_data database which contains incorrect user information. Then you will need to drop the payment_Info table from the 2004_data database as it contains sensitive and outdated information. Once the incorrect and outdated information has been removed, you need to create a new database named customer_info and table within that database called payment_info. The payment_info table should have the following characteristics:

  • column1 - Name is cust_id, numeric type is INT, auto increment, primary key
  • column2 - Name is user_name, string type is VARCHAR(50), unique key
  • column3 - Name is card_name, string type is INT
  • column4 - Name is purchase_item, string type is VARCHAR(255

Additional Information:

  • Tasks in the MySQL database should be performed as the root user.
  • Use the following password to login to the MySQL server as the root user: Linux4me!
  • Do not update the password for the MySQL root user as it is used for grading purposes.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?