Basic MySQL In Linux

This article aims to teach you basic MySQL in Linux and show you how to install it on Ubuntu and Centos and it will be working on all versions of them.

Before learning basic MySQL let’s see what MySQL is.

What is MySQL?

MySQL is an open-source relational database management system (RDBMS) with a client-server model. RDBMS is a software or service used to create and manage databases based on a relational model.

MySQL installation Requirements

To install MySQL in Linux you need to log in as a non-root user on your server.

Basic MySQL In Linux

How to install MySQL in Linux

You can install MySQL on Ubuntu with the following command:

sudo apt-get install mysql-server

You can install MySQL on Centos with the following command:

sudo yum install mysql-server
/etc/init.d/mysqld start

How to Secure MySQL

After installation is completed, you should run some commands for securing MySQL and set a password for it So Enter the following command to make the MYSQL security settings.


After entering press enter once and enter the MySQL login password. (default password is empty)

In the following steps, answer the other questions to your liking. It is suggested that you answer Y in all the questions to set the best state.

Work with MySQL

How to access the MySQL shell

When the installation of MySQL in Linux is finished you can access the MySQL shell with the following command:

mysql -u root –p

You should enter the root MySQL password after that you can build your MySQL database.

Note: don’t forget to end your commands with “;”. MySQL commands are usually written in uppercase.

How to create and delete a MySQL database

You can create a database in MySQL in Linux with the following command.

For example, create a database named orcacore:


Then you can check available databases with the following command:


You can also delete a database easily with the following command:


If you check your available databases there is no more a database named orcacore.

How to Access a MySQL Database

Into Your MySQL in Linux, You can put information in your new database. Open your database with the following command:

USE orcacore;

Then you can see its tables with the following command:

SHOW tables;

Because it is a new database there is nothing to show.

Let’s see how to create a MySQL table for your database.

How to create a MySQL table

You can create a table with the CREATE TABLE command in MySQL. For example:

CREATE TABLE orca (name VARCHAR(20),
age VARCHAR(10),
email VARCHAR(20)

This command will create a table named orca within the directory, orcacore.
And the columns are limited by the VARCHAR.

You can see tables with the SHOW TABLES command.

Add information to a MySQL table

In MySQL in Linux, you can use the format below to put your information into the table.

INSERT INTO `orcacore` (`name`, `age`,`email`) VALUES (“user1”,’25’,”[email protected]”);

You can look at your table with the following command:


How to update information in the table

You can use the below format to update your information in the table.

UPDATE `orca` 
`age` = '32' 
WHERE `orca`.`name` ='user1';

How to add and delete a column

You can easily add a column with the following command:

ALTER TABLE orca ADD lastname VARCHAR(40);

If you want that your column is in a specific place use:

ALTER TABLE orca ADD lastname VARCHAR(40) AFTER name;

You can also delete a column with DROP:

ALTER TABLE orca DROP lastname;

You can easily delete a row with the following command:

DELETE from [table name] where [column name]=[field text];


At this point, you learn a basic Mysql and you can create tables, add and delete columns, etc.

Hope you enjoy this article about basic MySQL in Linux.

For more articles about Linux, you can visit the Linux Tutorials section on the orcacore website.


Please enter your comment!
Please enter your name here

Latest Articles


Most Popular