Install Mysql In Ubuntu

This Tutorial we learn About How to Install MySQL Ubuntu 20.04 and also learn how to configure databases, backup, and restore databases. If you want to learn how to install MySQL in Linux/CentOS 8, then click on the link below.

INSTALL MYSQL 8 & IN RHEL/CENTOS 8 

MySQL is the world’s most popular open-source database system for many excellent reasons. First, it is open-source, which means anyone can use it for a wide variety of tasks for free. Best of all, MySQL is included in
many platform repositories, making it easy to get and install. If your platform doesn’t include MySQL in the repository (such as aptitude), you can download it from the MySQL web site.

Released in 1995, has become the most popular open-source database system. The popularity of MySQL and phpMyAdmin has allowed many non-IT specialists to build dynamic websites with a MySQL backend. good data structures for MySQL. It teaches how to plan the data structure and how to implement it physically using MySQL’s model.

MySQL is a full-featured relational database management system. It is very stable and has proven itself over time. MySQL has been in production for over 10 years. MySQL is a multi-threaded server. Multi-threaded means that every time someone establishes a connection with the server, the server program creates a thread or process to handle that client’s requests. This makes for an extremely fast server. In effect, every client who connects to a MySQL server gets his or her own thread.

Upgrade the System

First open the Ubuntu terminal ( Hotkey to Open ubuntu Terminal press CTRL +ALT+t) and Type bellow command Run the following command to update and upgrade the Ubuntu system.

$ sudo apt update

$sudo apt upgrade

Install MySQL packages

After the system updates and upgrades successfully are complete, you can install MySQL ubuntu the package in the system, type the following command to install the package of the file.

Install MySQL packages

Configuring MySQL

First Install MySQL in ubuntu then Run MySQL_secure_installation to strong MySQL security like Password Validation Policy, remove anonymous users, Disallow Users remote login, remove test database, and reload privilege.

Configuring MySQL
  • Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
  • Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
  • Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
  • Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

Start MySQL service and check Status

After Install MySQL package, check whether the MySQL server is running or not If the MySQL service is not running, then start it manually, but if the problem is coming then you can check it by checking the log file /var/log/message, /var/log/MySQL and find out why the service is not starting.

Start MySQL service and check Status

Check Ubuntu MySQL Version

In this tutorials we learning About check MySQL latest version

Check Ubuntu MySQL Version

connect to the MySQL using the root MySQL account first open the Ubuntu terminal ( shortcut to Open ubuntu Terminal press CTRL +ALT+t) and Type bellow command. Login with root password which was set earlier during MYSQL_ SECURE_INSTALLATION.

$mysql –user=root –password=the_mysql_root_password

$mysql -u=root -p=the_mysql_root_password

After login successfully in Mysql you can create databases and tables, Import exiting data backup, Create Users.

ogin successfully in Mysql

Restore database in Ubuntu

It is necessary to backup the file every day or week, you can take the backup to a local drive (in a directory or drive) or to an external drive such as an external hard drive, tape drive, pen drive, or network. You can easily restore it whenever there is a problem in a database.

You can take the backup manually or Automatically. You can back up the database in two ways, first, take a backup of a specific database second You can backup simultaneously all the databases created in the system.

backup a single database ( specific database)

mysqldump -u [username] -p [database] > name of the backup sql.sql;

backup  a single database

Backup all database;

Backup all database;

Restore database in Ubuntu.

When a problem occurs in MySQL you can restore the latest or working database. Before restoring the database, you have to login with root account and create a dummy database.To restore the MySQL Database, type the following command.

Restore database in Ubuntu.

How to Use Mysql

how to Create Database in MySQL

You can create a database of any name if it does not exist in the database server.

$create database database_name;

mysql > create database simitech;

show database: With the help of show command, you can display the list of databases created in the system.

show database

Use database: With the help of the use command, you can change the database or use the database.

$use database_name;

Use database

Create Table in the specific databases

$ mysql> create table book(book_id INT NOT NULL AUTO_INCREMENT,book_title VARCHAR
(100) NOT NULL,book_auther VARCHAR(100) NOT NULL,submission_date DATE, PRIMARY KEY(book_id));

Create Table in the specific databases

SHOW TABLES: With the help of this command, we can show the tables created in the database.

SHOW TABLES

show the tables column detail

 tables column

Create User In Ubuntu MySQL

MySQL server is an open-source relational database management system. Where you can create one or more user accounts. At the time of installation of MySQL, only one user is created, which is called a root account or administrative account. By default root account have all permissions.now we create other users.

To create a new MySQL user account, run the following command

mysql > CREATE USER ‘newuser’@’localhost’ IDENTIFIED BY ‘user_password’;

replace newuser with the new user name, and user_password with the user password.

Create User In Ubuntu MySQL

in the Above command, the user will only be able to access the localhost MySQL server, meaning if the user has to do some work then the file survey will have direct access. The user will directly access the MySQL, he does not have access to the MySQL from a remote IP Address.

If you create a MySQL user with the following command, you can access the MySQL remote IP Address.

Create User In Ubuntu MySQL with IP Privileged

To create a user that can connect from any host, use the '%' wildcard as a host part.

Create User In Ubuntu MySQL with All Priviledge

display the list of all the users created in the MySQL .

display  the list of all the users created in the MySQL

Remove an Existing MySQL User Account.

mysql > DROP USER ‘exiting-user-name’@’localhost’;

Remove an Existing MySQL User Account.

Uninstall MySQL in Ubuntu

Assume that your MySQL database is hanging and not getting started, or not allowing you to log in to the database, and tried to troubleshoot but failed, then in this case you have the last option to uninstall or remove MySQL from the and Install again. then restore the backup database As we have learned earlier.

Remove MySQL related all package from Your Ubuntu system.

$ sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*
Uninstall MySQL in Ubuntu

Remove MySQL configuration and data. If you have changed database location in your MySQL configuration, you need to replace /var/lib/mysql according to it.

$ sudo rm -rf /etc/mysql /var/lib/mysql

Remove MySQL configuration and data

Remove unnecessary packages.

Remove unnecessary packages.

Conclusion

This Tutorials We learned about how to install MySQL In Ubuntu 20.04 Step By steps hope that now you are comfortable with MySQL.If your problem is still not solved share your Problem via comments.

Related Posts