Linux Tutorial

Linux File/Directory Management

Linux Packaging And Compression

Vim Text Editor

Linux Text Processing

Linux Software Installation

Linux User/User Group Management

Linux Permission Management

Linux Filesystem Management

Linux Advanced Filesystem Management

Linux System Management

Linux Backup and Recovery

Linux System Service Management

Linux System Log Management

Linux Boot Management

LAMP/LNMP Environment

SELinux Management

Install MySQL in Linux

In this tutorial, we'll go through the process of installing MySQL on Linux. MySQL is a popular open-source relational database management system (RDBMS) that is widely used for web applications and other software systems. We will be using Ubuntu for this tutorial, but the process is similar for other Linux distributions like Debian and CentOS.

Step 1: Update Package Lists

Before installing MySQL, it's a good idea to update your package lists to ensure you're installing the latest version. Run the following command:

sudo apt update

Step 2: Install MySQL Server

To install the MySQL server package, run the following command:

sudo apt install mysql-server

During the installation process, you might be prompted to confirm the installation by typing "Y" and pressing Enter.

Step 3: Configure MySQL Security Settings

Once the installation is complete, it is recommended to run the MySQL security script to improve the security of your MySQL installation. This script will prompt you to set a password for the MySQL root user and to configure other security settings. Run the following command:

sudo mysql_secure_installation

Follow the prompts to configure your MySQL installation. You can choose to set a password policy, remove anonymous users, disallow root login remotely, and remove the test database.

Step 4: Check MySQL Status

After completing the security setup, you can check the status of your MySQL server by running the following command:

sudo systemctl status mysql

If the installation was successful, you should see the MySQL server status as "active (running)".

Step 5: Start, Stop, or Restart MySQL Server

To start, stop, or restart the MySQL server, use the following commands:

  • Start MySQL server:

    sudo systemctl start mysql
    
  • Stop MySQL server:

    sudo systemctl stop mysql
    
  • Restart MySQL server:

    sudo systemctl restart mysql
    

Step 6: Enable MySQL Server on Startup

To enable the MySQL server to start automatically when your system boots, run the following command:

sudo systemctl enable mysql

Step 7: Log in to MySQL

You can log in to your MySQL server using the MySQL command-line client. Run the following command, replacing "root" with your MySQL username if you have a different one:

sudo mysql -u root -p

Enter your MySQL password when prompted, and you will be logged in to the MySQL server. You can now run SQL queries and manage your databases.

Conclusion

By following these steps, you have successfully installed MySQL on your Linux system. You can now create and manage databases, tables, and users as needed for your applications.

  1. How to set up MySQL on Linux: Setting up MySQL on Linux involves installing the MySQL server, configuring it, and potentially securing it. The steps are generally as follows:

    sudo apt-get update
    sudo apt-get install mysql-server
    sudo mysql_secure_installation
    
  2. Installing MySQL server on Ubuntu/Linux: On Ubuntu, use the following commands to install MySQL Server:

    sudo apt-get update
    sudo apt-get install mysql-server
    sudo mysql_secure_installation
    
  3. Step-by-step MySQL installation on CentOS: CentOS uses the yum package manager for installation. Follow these steps:

    sudo yum install mysql-server
    sudo systemctl start mysqld
    sudo systemctl enable mysqld
    sudo mysql_secure_installation
    
  4. MySQL installation and configuration in Debian: For Debian-based systems, like Ubuntu, use the following commands:

    sudo apt-get update
    sudo apt-get install mysql-server
    sudo mysql_secure_installation
    
  5. Installing MySQL on Red Hat Linux: Red Hat and CentOS are similar. Use the yum package manager:

    sudo yum install mysql-server
    sudo systemctl start mysqld
    sudo systemctl enable mysqld
    sudo mysql_secure_installation
    
  6. Setting up MySQL on a Linux server: Once installed, you might need to configure MySQL, create databases, and set up users. For example:

    mysql -u root -p
    CREATE DATABASE mydatabase;
    CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
    GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost';
    FLUSH PRIVILEGES;