Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Databases»MySQL»How To Install MySQL Server on Ubuntu 22.04

    How To Install MySQL Server on Ubuntu 22.04

    RahulBy RahulApril 6, 20224 Mins ReadUpdated:April 6, 2022

    MySQL is the most popular Open Source SQL database management system. It is developed and supported by Oracle Corporation. MySQL is widely used on Linux systems. Now MySQL providers also provide their own apt repository for installing MySQL on Ubuntu systems.

    This tutorial will help you to install the MySQL server on Ubuntu 22.04 Jammy Jellyfish Linux systems.

    Prerequisities

    You must have a running Ubuntu 20.04 Linux system with sudo privileges user access.

    Step 1 – Installing MySQL on Ubuntu 22.04

    The default Ubuntu repositories contain MySQL 8.0. Which can be installed directly using the package manager without adding third-party PPA.

    To install the available MySQL server version, execute the following command.

    sudo apt-get install mysql-server 
    

    Press ‘y’ for any confirmation asked by the installer.

    Once the installation is finished, you can secure the MySQL server by executing the following command.

    sudo mysql_secure_installation 
    

    You will go through a wizard of questions to secure the MySQL server. Follow the onscreen instructions below:

    1. Press ‘y’ to enable validate password plugin. This will allow you to set a strict password policy for user accounts.
      VALIDATE PASSWORD COMPONENT can be used to test passwords
      and improve security. It checks the strength of password
      and allows the users to set only those passwords which are
      secure enough. Would you like to setup VALIDATE PASSWORD component?
      
      Press y|Y for Yes, any other key for No: y
      
    2. Chose the password complexity level. Read the all 3 options and choose one:
      LOW    Length >= 8
      MEDIUM Length >= 8, numeric, mixed case, and special characters
      STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
      
      Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
      
    3. Enter a new password and re-enter it. Make sure it matches the complexity level as described above.
      New password: *************
      Re-enter new password: *************
      
    4. Press ‘y’ to continue with provided password.
      Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
      
    5. Remove default anonymous users from MySQL server:
      Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
      
    6. Disable root login from remote systems
      Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
      
    7. Remove test database form MySQL created by default during installation.
      Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
      
    8. Reload all privileges to apply above changes immediately.
      Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
      

    You have secured the MySQL server in the LAMP stack on Ubuntu 22.04 Linux system.

    Step 2 – Connect to MySQL Server

    Remember that the above password set for the root accounts is used for remote users only. To log in from the same system, just type mysql on terminal.

    sudo mysql 
    
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 14
    Server version: 8.0.28-0ubuntu4 (Ubuntu)
    
    Copyright (c) 2000, 2022, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    

    Step 3 – Creating Database and Users

    Here is few example queries to create database and users in MySQL server.

    • Create a database named ‘mydb’.
      CREATE DATABASE mydb; 
      
    • Next, create a user named ‘myuser’ accessible from ‘localhost’ only.
      CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'secure_password_'; 
      
    • Grant permissions on database to user.
      GRANT ALL ON mydb.* to 'myuser'@'localhost'; 
      
    • Apply the permission changes at runtime.
      FLUSH PRIVILEGES; 
      

    Step 4 – Manage MySQL Service

    • To check the database server status.
      sudo systemctl status mysql 
      
    • Use below command to start MySQL server.
      sudo systemctl start mysql 
      
    • To stop MySQL server:
      sudo systemctl stop mysql 
      
    • Restart MySQL database server, type:
      sudo systemctl restart mysql 
      

    Step 5 – Uninstall (Remove) MySQL Server

    If you no longer need to use the MySQL server, uninstall it from your server.

    Warning – This will remove all databases from your system. Please backup all the databases in a safe place.

    To remove MySQL server type:

    sudo apt purge mysql-server-* 
    

    To completely uninstall MySQL, remove the following folders as well.

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

    Conclusion

    This tutorial helped you to install the MySQL server on Ubuntu 20.04 LTS Linux system. Also includes instructions to secure the database server and uninstall it.

    database MySQL
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow To Install LAMP Stack on Ubuntu 22.04 LTS
    Next Article How To Install Linux, Nginx, MySQL, & PHP (LEMP Stack) on Ubuntu 22.04

    Related Posts

    How To Install Linux, Nginx, MySQL, & PHP (LEMP Stack) on Ubuntu 22.04

    Updated:April 7, 20227 Mins Read

    How To Install LAMP Stack on Ubuntu 22.04 LTS

    Updated:April 20, 20225 Mins Read

    How To Install MariaDB on Debian 11

    4 Mins Read

    How to Install Redis on Debian 11 Linux

    Updated:September 16, 20213 Mins Read

    How to Check the PostgreSQL Version

    Updated:August 6, 20212 Mins Read

    How to Rename MySQL Database

    Updated:July 26, 20213 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.