Archive Blog: MySQL CLI is just better…

Nabil Ahsan
3 min readFeb 16, 2024

--

Full disclosure I wrote this back when I was studying Computer Science at University of Houston. I rediscovered this after 5 years and I didn’t edit any of the content. I was using Linux Mint at that time.

My database class is a total mess. Every day is a struggle because of the structure of the class and how it’s being taught.

It’s 2018 and yet, we have to use Microsoft Word (Note: 2003 version) and the shapes assigned by our Professor to do the ERD diagram. Formatting gets messed up every time I try to make changes with my partner and it’s been driving us crazy.

For our second project, we have to start working with SQL. But, we are asked to use Oracle’s SQL Developer, which is another pain because the University-made Oracle accounts weren’t working. So, I decided the next best thing…

I’ll use VS Code and the MySQL CLI method.

I had to create queries from a less than readable collection of table. Ugh

As a Linux user, I have a distinct hatred for Microsoft products. My first ever Computer Science class shoved Visual Studio (ya the big one) down our throats. Don’t even get me started on Windows Updates.

VS Code changed all of that. I still hate the other stuff. But, not VS Code. It’s got Git integration, tons of plugins, and just looks damn good. I use it for EVERYTHING.

So when we got this assignment, I was going to try to figure out how to stick to my current workflow without installing anything that would otherwise slow me down.

First thing’s first, open up your Terminal. You can do it through VS Code if you want (Yup, it comes with a terminal). Now, gotta make sure everything is updated:

sudo apt-get update && sudo apt-get upgrade

Now, let’s go and install MySQL:

sudo apt-get install mysql-server

Once that is done, you can go ahead and run the command below:

sudo mysql_secure_installation

Now is the process of choosing your root password. It will prompt you to purge old databases, old user accounts, etc. In short, a fresh start.

After a lot of mistrials, I went sudo su and then executed mysql -u root -p and then, entered my password and BOOM, MySQL is now working.

Of course, we are working with VS Code. As a safe measure, I opened a new folder and made a lab1.sql file in that folder. I also hastily installed whatever the top MSSQL/MySQL plugins that I found.

Switching over to the terminal. Go ahead an type in show databases; to show the existing databases.

REMEMBER, every SQL statement ends with a semicolon (;)

You will be shown something similar to this (Mine is testDB):

The write create database [name]; without the brackets and that will create a database of your choice.

Now, you have to execute use [name]; so you can start using the database you just created. Just in case, execute select database() just to make sure you are in the chosen database.

Now, this isn’t a MySQL tutorial, but it is always a good practice to go through whatever data you are provided. Make notes of the data types and constraints. For example, TutorFirstName is CHAR(45). Make sure if you have that attribute in any other tables, it’s the same CHAR(45).

That’s it then. Now you can go ahead and do whatever you want with the database. Here is a helpful cheat sheet I found for the MySQL commands: https://gist.github.com/hofmannsven/9164408

--

--

Nabil Ahsan
Nabil Ahsan

No responses yet