To install MySQL 8 on an Ubuntu system, follow these steps:
Step 1: Update System Packages
Update the package index to ensure your system is up-to-date.
sudo apt update
sudo apt upgrade -y
Step 2: Install MySQL APT Repository
Ubuntu's default repository may not include MySQL 8. To get MySQL 8, you need to download the MySQL APT repository.
- Download the repository package:
wget https://dev.mysql.com/get/mysql-apt-config_0.8.29-1_all.deb
- Install the downloaded package:
sudo dpkg -i mysql-apt-config_0.8.29-1_all.deb
- During installation:
- You will see a configuration screen.
- Select MySQL Server & Cluster (currently MySQL 8.0).
- Press OK to continue.
Step 3: Install MySQL Server
Once the repository is set up, install MySQL 8:
sudo apt update
sudo apt install mysql-server -y
Step 4: Secure MySQL Installation
After installation, secure the MySQL setup using the following command:
sudo mysql_secure_installation
You will be prompted to:
- Set a root password.
- Remove anonymous users.
- Disable root login remotely.
- Remove test databases.
- Reload privileges.
Answer Y
(yes) to all prompts for a secure configuration.
Step 5: Verify MySQL Service
- Ensure MySQL is running:
sudo systemctl status mysql
- Enable MySQL to start on boot:
sudo systemctl enable mysql
Step 6: Connect to MySQL
You can connect to MySQL as the root user:
sudo mysql -u root -p
Enter the root password you set earlier.
Optional: Allow Remote Access
If you want to allow remote connections to your MySQL server:
- Edit the MySQL configuration file:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
- Find the line with
bind-address
and change it to:
bind-address = 0.0.0.0
- Restart MySQL:
sudo systemctl restart mysql
- Open MySQL and grant remote access:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
- Allow MySQL port (3306) through the firewall:
sudo ufw allow 3306
Final Notes
You now have MySQL 8 installed and running on Ubuntu. You can start creating databases, users, and tables.
Let me know if you encounter any issues! đ
No comments:
Post a Comment