0% found this document useful (0 votes)
34 views10 pages

Using Mysql Command Line

1. The document discusses using the MySQL command line interface to interact with MySQL databases. It describes downloading a sample database file, creating a new database, restoring the sample database tables and data, exploring and querying the tables, and backing up a table to create a dump file. 2. Key commands covered include using mysql to access the database, source to restore from a dump file, show tables to list tables, describe to view a table structure, select to query data, and mysqldump to create a backup dump file. 3. The hands-on lab guides the user through creating a database, restoring sample data, exploring tables, querying data, and backing up a single table to a dump file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views10 pages

Using Mysql Command Line

1. The document discusses using the MySQL command line interface to interact with MySQL databases. It describes downloading a sample database file, creating a new database, restoring the sample database tables and data, exploring and querying the tables, and backing up a table to create a dump file. 2. Key commands covered include using mysql to access the database, source to restore from a dump file, show tables to list tables, describe to view a table structure, select to query data, and mysqldump to create a backup dump file. 3. The hands-on lab guides the user through creating a database, restoring sample data, exploring tables, querying data, and backing up a single table to a dump file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

USING MYSQL COMMAND LINE

MySQL was first developed by a Swedish company MySQL AB and named after My, the
daughter of one of the co-founders of MySQL AB, Monty Widenius. The company was later
acquired by Sun Microsystems, which in turn was acquired by Oracle Corporation. The dolphin
in the MySQL logo is named Sakila, which was chosen from a list of suggestions made in a
‘name the dolphin’ contest. MySQL soared in popularity in the late 1990s and early 2000s,
partly because it was a key component in the LAMP (Linux operating system, Apache web
server, MySQL database, and PHP scripting language) stack which was being used to build
many popular web sites at the time. MySQL is available under dual license: the open source
GNU GPL and a commercial license for applications and solutions that embed MySQL.
Because the GNU GPL is open source, there have been various forks of MySQL, the most
prominent being MariaDB which is led by some of the original developers of MySQL.
MySQL is an object-relational database management system. It is a popular low-maintenance
database and is available in various flavors and editions, including a clustered version for
demanding workloads. It’s available to use in a range of ways to suit your needs. You can
download and install the free Community Edition under a GNU General Public License and you
can embed this in your own applications. Alternatively, you can purchase, download, and install
commercial editions, such as Standard, Enterprise, and Cluster versions, which include
additional functionality. MySQL is also available in the cloud. You can self-manage in virtual
machine images or containers or you can use a managed service such as IBM Cloud, Amazon
RDS for MySQL, Azure Database for MySQL, or Google Cloud SQL for MySQL. There is a
range of tools that you can use to work with your databases, including the mysql command line
interface, the MySQL Workbench desktop application for Windows, Linux, and Mac OS
versions of MySQL, and the popular third-party web interface, phpMyAdmin.

mysql command line interface enables you to issue commands to interact with your MySQL
server and data. These commands can be typed directly in the prompt for interactive use or run
from a text file that you invoke from the command prompt.
MySQL Workbench is a visual database design tool that integrates SQL development,
administration, database design, creation, and maintenance into a single development
environment for the MySQL database system.
phpMyAdmin is a popular third-party web-based graphical user interface (GUI) tool, that you
can use to administer your MySQL databases. When you first connect to the server, you see the
server information and the system databases. You can then create your own user databases and
use the different tabs to interact with them. You can create databases and tables, load and query
data, and import and export data using phpMyAdmin.
important:
This project awards a certificate to those who successfully complete the hands-on lab exercise
and complete the quiz. In the next step, you will launch your lab exercise in a separate browser
tab with Cloud IDE.
When you complete your lab exercise in the Cloud IDE, please certify completion and come
back to this browser tab to take the quiz and to receive your certificate.

You will be using Skills Network Labs (SN Labs) Cloud IDE to do this project.  SN Labs Cloud
IDE is a great way to do projects without downloading, installing, configuring, and integrating
software on your own computer. Instead, you do everything in a web browser.
SN Labs Cloud IDE has two major components:
1. Instructions you will be following to do this project
2. Integrated Development Environment (IDE) where you will use the terminal, write
code, and do all other tasks you typically do in an IDE:

If you have used Integrated Development Environments (IDE) like Visual Studio Code (VS
Code) you will be instantly familiar with the Cloud IDE provided by the SN Labs. You will be
using the terminal most often but you will have access to all other functions of the IDE. When
your project launches, you can open a terminal session from the core menu. Go to Terminal >
New Terminal to open a terminal.
Next steps
Next, you will launch your lab exercise in Cloud IDE. Cloud IDE will launch in a separate
browser tab.
When you complete your lab exercise in the Cloud IDE, please certify completion and come
back to this browser tab to take the quiz and to receive your certificate.
Task A: Create a database
1. Go to Terminal > New Terminal to open a terminal from the side by side launched
Cloud IDE.
2. Copy the command below by clicking on the little copy button on the bottom right of the
codeblock and then paste it into the terminal using Ctrl + V (Mac: ⌘ + V) to fetch
the sakilamysqldump.sql file to the Cloud IDE.

wget https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBM-DB0110EN-
SkillsNetwork/datasets/sakila/sakila_mysql_dump.sql

3. Start the MySQL service session in the Cloud IDE using the command below in the
terminal:

start_mysql

4. Initiate the mysql command prompt session within MySQL service session using the
command below in the terminal:

mysql --host=127.0.0.1 --port=3306 --user=root --password


MTg5NDAtc291bWl0
When prompted, enter the password that was displayed when MySQL started up, as
shown in the screenshot below.

MTg5NDAtc291bWl0

Please note, you won't be able to see your password when typing it in. Not to worry, this
is expected!

5. Enter your MySQL service session password from the highlighted location of the
terminal shown in the image above. Note down your MySQL service session password
because you may need to use it later in the lab.
6. Create a new database sakila using the command below in the terminal and proceed to
Task B:

create database sakila;

Task B: Restore the structure and data of a table


1. To use the newly created empty sakila database, use the command below in the terminal:

use sakila;
2. Restore the sakila mysql dump file (containing the sakila database table definitions and
data) to the newly created empty sakila database. A dump file is a text file that contains
the data from a database in the form of SQL statements. This file can be imported using
the command line with the following command:

source sakila_mysql_dump.sql;

Note: You can use the source command to restore the database dump file within the
mysql command prompt. To restore the database dump file outside of the mysql
command prompt, you can use the mysql --host=127.0.0.1 --port=3306 --user=root --
password sakila < sakila_mysql_dump.sql command after quitting the mysql command
prompt session with command \q.

Task C: Explore and query tables


1. To list all the tables names from the sakila database, use the command below in the
terminal:

SHOW FULL TABLES WHERE table_type = 'BASE TABLE';


The Table_type for these tables is BASE TABLE. BASE TABLE means that it is a
table as opposed to a view (VIEW) or an INFORMATION_SCHEMA view (SYSTEM
VIEW).

2. Explore the structure of the staff table using the command below in the terminal:

DESCRIBE staff;

2. To understand the output, see the following table:


Column
Definition
Name
Field Name of the column.
Type Data type of the column.
Displays YES if column can contain NULL values and NO if not.
Null
Notice how the primary key displays NO.
Displays the value PRI if the column is a primary key, UNI if the
column is a unique key, and MUL if the column is a non-unique
index in which one value can appear multiple times. If there is no
Key value displayed, then the column isn't indexed or it's indexed as a
secondary column. Please note, that if more than one of these
values applies to the column, the value that appears will be
displayed based on the following order: PRI, UNI, and MUL.
The default value of the column. If the column's value has
Default specifically been set as NULL, then the value that appears will be
NULL.
Extra Any additional information about a column.
3. Now retrieve all the records from the staff table using the command below in the
terminal:

SELECT * FROM staff;

4. Quit the MySQL command prompt session using the command below in the terminal and
proceed to Task D:

\q

Task D: Dump/backup tables from a database


1. Finally, dump/backup the staff table from the database using the command below in the
terminal:

mysqldump --host=127.0.0.1 --port=3306 --user=root --password sakila staff >


sakila_staff_mysql_dump.sql

This command will back up the staff table from the sakila database into a file


called sakilastaffmysql_dump.sql.

2. Enter your MySQL service session password.

3. To view the contents of the dump file within the terminal, use the command below:

cat sakila_staff_mysql_dump.sql

You might also like