Working on MySQL Server on Debian 11

Reading Time: 3 minutes

Working on MySQL Server on Debian 11 is an article that provides some examples of how to create a database, how to create a table, and how to input data into this table.

Before anything, I would like to share some articles that we have written:

— Installing Linux Debian 11:
https://www.dpcvirtualtips.com/installing-linux-debian-11/

— Installing MySQL Server on Debian 11:
https://www.dpcvirtualtips.com/installing-mysql-db-on-debian-11/

First and Foremost, How can I access the MySQL Server?

In this case, for instance, we are considering you already installed the MySQL server in your OS.
So, access the MySQL server command line locally, using the following command:

mysql -u root -p

After that, we can type a command to see all available databases inside the MySQL server.
Here, we can see all the databases that were installed during the MySQL server installation:

show databases;

Creating a Database

Our aim here is just to create a simple database. In this case, the database name is “SampleDB”.
We can create and use this database by executing the following commands:

CREATE DATABASE IF NOT EXISTS `SampleDB` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

USE `SampleDB`;
This image has an empty alt attribute; its file name is image-138.png

Now we can see the database “SampleDB”:

Creating a Table Inside the Database

So, now we will create a simple table under the database that we already created in the above step.
In this case, for instance, the table name is “SampleTable”:

CREATE TABLE `SampleTable` (
  `first_name` varchar(255) NOT NULL,
  `last_name` varchar(255) NOT NULL,
  `gender` varchar(255) NOT NULL,
  `address` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

The command “show tables” can be used to show all available tables inside a specific database!

If you need to see the column details, you can use the command:

show columns from SampleTable;

Inserting Data into a Table

At this moment, the table “SampleTable” is clear because we created it a few moments ago.
We can use the SQL command “input” just to input some data into this table.

In the following command, we will input data into the table “SampleTable”:

INSERT INTO `SampleTable` (`first_name`, `last_name`, `gender`, `address`, `email`) VALUES
('First Name', 'Last Name', 'Male', 'My Address, Number', 'first.lastname@mail.com');

COMMIT;

We can use the SQL command “select” just to see the data inside a table. In this case, for instance, we are executing a command to see all data inside the table “SampleTable”:

select * from SampleTable;

Wrapping This Up

So, this is not a SQL course or something like that 🙂
But the main aim here is to provide the basic knowledge to create your database and table, just to perform some tests without depending on the DEV team or something like that 🙂

Feel free to reach me in case of additional things or questions!