Using Mysql Command Line
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:
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:
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.
2. Explore the structure of the staff table using the command below in the terminal:
DESCRIBE staff;
4. Quit the MySQL command prompt session using the command below in the terminal and
proceed to Task D:
\q
3. To view the contents of the dump file within the terminal, use the command below:
cat sakila_staff_mysql_dump.sql