Installing MySQL on Linux (Ubuntu)
Step 1: Update Package Lists
Open a terminal and run the following commands to make sure that the package lists are up-to-date:
sudo apt updateStep 2: Install MySQL Server
Next, use the following command to install the MySQL server:
sudo apt install mysql-serverDuring the installation process, you will be prompted to set a root password for MySQL.
Step 3: Start and Enable MySQL
After the installation is complete, start the MySQL service and enable it to start on boot with:
sudo systemctl start mysql
sudo systemctl enable mysqlStep 4: Configure MySQL Security
Run the MySQL security script to improve the security of your MySQL installation:
sudo mysql_secure_installationThis script will prompt you to perform several actions like setting a new root password, removing anonymous users, and disallowing remote root login.
Step 5: Access MySQL Shell
To access the MySQL shell, use the following command and enter the root password you set during the installation:
sudo mysql -u root -pStep 6: Create Additional Users (Optional)
You can create additional MySQL users if needed. This is recommended for better security.
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;Replace 'username' with the desired username and 'password' with a strong password.
Step 7: Install MySQL Client (Optional)
If you need to connect to MySQL from a remote machine, you can install the MySQL client:
sudo apt install mysql-clientStep 8: Verify Installation
You can verify the installation by accessing MySQL from the command line or by using a MySQL client.
That’s it! You now have MySQL installed on your Ubuntu Linux system. You can start creating databases and tables, and using MySQL for your applications.