Introduction
MySQL is one of the most popular open-source relational database management systems. It allows us to implement database operations on tables, rows, columns, and indexes. Mysql defines relationships in the form of tables also known as relations. it is faster than other databases, so it can also handle large data sets.
This article will explain how to install Mysql on ubuntu flavors.
Install Mysql
The steps below will show how to install Mysql on the Ubuntu operating system.
- Update the software repository before installing new software.
$ sudo apt update
- After successfully updating the package repository Install Mysql using the below command.
$ sudo apt -y install mysql-server
- Verify that Mysql is installed correctly by checking the version of MySQL. Enter the following command.
$ mysql --version
- To improve the security of MySQL installation, use the below command:
$ sudo mysql_secure_installation
Choose one of the three levels of password validation and Enter the password to validate the password component.
PressY
then a few questions prompt for the security features pressY
(Recommended) for all questions.
Note: if you need the remote login option for your server, enter any key other thanY
for that prompt. - Verify that the MySQL server is running or not using the below command.
$ sudo systemctl status mysql
Test Mysql
- log in to MySQL using the following command:
$ sudo mysql -u root
- Create a new user in Mysql.
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'password';
- Grant access to the new user using the
GRANT PRIVILEGE
command to all the databases.GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, REFERENCES, RELOAD ON *.* TO 'myuser'@'localhost' WITH GRANT OPTION;
- Create a new database in Mysql.
CREATE DATABASE my_database;
- Show databases using the below command.
SHOW DATABASES;
- Create a table for the database in Mysql.
USE my_database;
CREATE TABLE my_table (name VARCHAR(20), address VARCHAR(20)); - To show your created table use the below command.
SHOW TABLES;