Getting Started on How to use MySQL Shell


Overview
This article explains how to use SQL commands with MySQL Shell to create databases and view information in a database.
Materials
MySQL (1)
MySQL Shell
When downloading MySQL, it installs MySQL workbench, which is an interactive graphical user interface and shell where the user can view, make and perform changes to a database. Another software is also installed called MySQL Shell, which this tutorial will focus on using this software if people prefer just using a shell.
During the installation of MySQL, it asks the user to make a database. Remember the username and password of the created database, because both are needed to enter the database. In this demonstration, the username of the database is called root.
Procedure
Using MySQL Shell to Access the Database
To check if the database was created, open MySQL Shell.
By default, it’s in JS or JavaScript mode. To switch to SQL mode, type the command “\sql” and press enter. Every command that’s typed into the shell, must be entered afterward to execute a shell command.
Clearing the MySQL Shell
If there are too many commands in the MySQL Shell, type “\! cls“ to clear the terminal and have a blank screen
\! cls
Connect to the database by running the “\connect” command. When using the connect command, the username of the database, localhost and the port the database runs on is needed. Below shows the syntax of connecting to a running database:
\connect username@localhost:port_number
Once again, in this tutorial, the username is root and the port number is 3306. When a database is running locally on a computer, the default port to run locally is 3306.
\connect root@localhost:3306
After running the command, enter a password. To access this database in the future, remember the username and password.
Then, run the command “show databases“ to check the current databases that are there
show databases;
To make a database, use the command “create database” and specify the name of the database
create database give_name_to_database;
Run the command, “show databases;” to see the changes
Aside from using the SQL workbench, the SQL shell is another way to create and edit databases.
Sources
Subscribe to my newsletter
Read articles from Andrew Dass directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Andrew Dass
Andrew Dass
On my free time, I like to learn more about hardware, software and different technologies. I publish articles about my recent learnings or the projects I have done.