How to Install and Configure MySQL on Linux
MySQL is a powerful open-source relational database management system that is widely used for various applications. Installing and configuring MySQL on a Linux system is a fundamental skill for anyone involved in database management or web development. In this guide, we'll walk you through the step-by-step process to install and configure MySQL on a Linux environment.
Prerequisites:
Before we begin, ensure that you have root or sudo access on your Linux server. Additionally, make sure your package manager is updated to the latest version.
Step 1: Update Package Lists
sudo apt update
Step 2: Install MySQL Server
sudo apt install mysql-server
Step 3: Start MySQL Service
sudo systemctl start mysql
Step 4: Secure MySQL Installation
sudo mysql_secure_installation
Follow the prompts to set a root password, remove anonymous users, disallow root login remotely, remove the test database, and reload privileges.
Step 5: Access MySQL Shell
sudo mysql -u root -p
Enter the root password when prompted.
Step 6: Create a New MySQL User and Database
CREATE DATABASE mydatabase;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
Replace 'mydatabase', 'myuser', and 'mypassword' with your preferred database name, username, and password.
Step 7: Exit MySQL Shell
exit;
Step 8: Test MySQL Connection
mysql -u myuser -p
Enter the password when prompted.
Step 9: Configure MySQL to Start on Boot
sudo systemctl enable mysql
Additional Tips:
Create a Database Backup:
mysqldump -u myuser -p mydatabase > backup.sql
Restore from Backup:
mysql -u myuser -p mydatabase < backup.sql
Change MySQL Port:
Edit MySQL configuration file:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Change the port number and restart MySQL:
sudo systemctl restart mysql
Related Searches and Questions asked:
That's it for this topic, Hope this article is useful. Thanks for Visiting us.