Trang chủ Linux Fedora Database Fedora Install MySQL 8.0 on Fedora 39 | Fedora 38

Install MySQL 8.0 on Fedora 39 | Fedora 38

MySQL là một hệ thống quản lý cơ sở dữ liệu quan hệ mã nguồn mở, được phát triển bởi Oracle Corporation. Phần mềm này được phát hành theo các điều khoản Giấy phép Công cộng GNU. Trong hướng dẫn này, chúng tôi sẽ hướng dẫn cách cài đặt, install MySQL 8.0 trên Fedora 39 | Fedora 38 Server hoặc Workstation. Nếu bạn đang sử dụng phiên bản cũ của MySQL Server (vd: 5.7), bạn có thể cần nâng cấp trực tiếp hoặc sao lưu toàn bộ dữ liệu, nâng cấp các gói và nhập lại toàn bộ dữ liệu cơ sở dữ liệu vào MySQL 8.0 mới cài đặt.

Hướng dẫn mới nhất của chúng tôi về cài đặt MySQL 8.0 là cho Ubuntu: Cách cài đặt MySQL 8.0 trên Ubuntu. Phiên bản MySQL có sẵn thông qua kho lưu trữ Fedora Modular là MySQL 5.7.

Add MySQL 8.0 community repository

Để cài đặt MySQL 8.0 trên Fedora, bạn cần thêm kho lưu trữ cộng đồng MySQL 8.0.

Add MySQL 8.0 repository to Fedora:

Chạy các lệnh sau từ terminal để cài đặt kho lưu trữ MySQL.

### Fedora 38 ###
sudo dnf -y install https://dev.mysql.com/get/mysql80-community-release-fc39-1.noarch.rpm

### Fedora 38 ###
sudo dnf -y install https://dev.mysql.com/get/mysql80-community-release-fc38-1.noarch.rpm

### Fedora 37 ###
sudo dnf -y install https://dev.mysql.com/get/mysql80-community-release-fc37-1.noarch.rpm

### Fedora 36 ###
sudo dnf -y install https://dev.mysql.com/get/mysql80-community-release-fc36-1.noarch.rpm

### Fedora 35 ###
sudo dnf -y install https://dev.mysql.com/get/mysql80-community-release-fc35-3.noarch.rpm

### Fedora 34 ###
sudo dnf -y install https://dev.mysql.com/get/mysql80-community-release-fc34-3.noarch.rpm

Việc này sẽ tạo một tệp kho lưu trữ tại /etc/yum.repos.d/mysql-community.repo

$ cat /etc/yum.repos.d/mysql-community.repo
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/fc/$releasever/$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022

[mysql-innovation-community]
name=MySQL Innovation Release Community Server
baseurl=http://repo.mysql.com/yum/mysql-innovation-community/fc/$releasever/$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/fc/$releasever/$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/fc/$releasever/$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022

[mysql-tools-innovation-community]
name=MySQL Tools Innovation Community
baseurl=http://repo.mysql.com/yum/mysql-tools-innovation-community/fc/$releasever/$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022

[mysql-cluster-innovation-community]
name=MySQL Cluster Innovation Release Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-innovation-community/fc/$releasever/$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022

Install MySQL Server 8.0 on Fedora

Sau khi đã thêm kho lưu trữ và xác nhận đã được kích hoạt, tiếp tục cài đặt MySQL 8.0 lên Fedora của bạn bằng cách chạy:

sudo dnf install mysql-community-server

Tiếp tục quy trình cài đặt MySQL 8.0 trên Fedora:

Transaction Summary
======================================================================================================================================================================================================
Install  67 Packages

Total download size: 57 M
Installed size: 330 M
Is this ok [y/N]: y

Cũng chấp nhận việc nhập khẩu các khóa GPG khi được yêu cầu.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                  29 MB/s |  57 MB     00:01
MySQL 8.0 Community Server                                                                                                                                            3.0 MB/s | 3.1 kB     00:00
Importing GPG key 0xA8D3785C:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: BCA4 3417 C3B4 85DD 128E C6D4 B7B3 B788 A8D3 785C
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
Is this ok [y/N]: y

Sau khi cài đặt xong, bạn có thể xem thông tin gói từ:

$ rpm -qi mysql-community-server
Name        : mysql-community-server
Version     : 8.0.35
Release     : 10.fc39
Architecture: x86_64
Install Date: Sat 11 Nov 2023 10:51:22 PM UTC
Group       : Unspecified
Size        : 116739321
License     : Copyright (c) 2000, 2023, Oracle and/or its affiliates. Under GPLv2 license as shown in the Description field.
Signature   : RSA/SHA256, Mon 16 Oct 2023 11:24:01 AM UTC, Key ID 467b942d3a79bd29
Source RPM  : mysql-community-8.0.35-10.fc39.src.rpm
Build Date  : Thu 12 Oct 2023 12:25:19 PM UTC
Build Host  : pb2-fedora39-01
Packager    : MySQL Release Engineering <mysql-build@oss.oracle.com>
Vendor      : Oracle and/or its affiliates
URL         : http://www.mysql.com/
Summary     : A very fast and reliable SQL database server
....

Configure MySQL server on Fedora

Sau khi cài đặt MySQL 8.0 trên Fedora, bạn cần cấu hình ban đầu để bảo mật nó.

1. Khởi động và bật dịch vụ mysqld:

sudo systemctl start mysqld.service && sudo systemctl enable mysqld.service

2. Sao chép mật khẩu ngẫu nhiên đã tạo ra cho người dùng root

sudo grep 'A temporary password' /var/log/mysqld.log |tail -1

Ghi chú mật khẩu được in ra:

A temporary password is generated for root@localhost: 1ph/axo>vJe;

3. Chạy MySQL Secure Installation để thay đổi mật khẩu root, Ngăn chặn đăng nhập từ xa của root, xóa người dùng ẩn danh và xóa cơ sở dữ liệu thử nghiệm.

$ sudo mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:

Xác thực bằng mật khẩu tạm thời đã tạo. Sau đó, cấu hình cài đặt MySQL 8.0 của bạn như dưới đây:

Change the password for root ? ((Press y|Y for Yes, any other key for No) : Yes

New password: 
Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?: Yes

Remove anonymous users?: Yes
Success.

Disallow root login remotely? : Yes
Success.

Remove test database and access to it? : Yes
 - Dropping test database...
Success.
 - Removing privileges on test database...
Success.

Reload privilege tables now? (Press y|Y for Yes) : Yes
Success.

All done!

4. Kết nối vào Cơ sở dữ liệu MySQL với người dùng root và tạo một cơ sở dữ liệu thử nghiệm.

$ sudo mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.33

Copyright (c) 2000, 2023, 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> SELECT version();
+-----------+
| version() |
+-----------+
| 8.0.33    |
+-----------+
1 row in set (0.00 sec)

Tạo một cơ sở dữ liệu và người dùng thử nghiệm

mysql> CREATE DATABASE test_db;
Query OK, 1 row affected (0.09 sec)

mysql> CREATE USER 'test_user'@'localhost' IDENTIFIED BY "Strong34S;#";
Query OK, 0 rows affected (0.04 sec)

mysql> GRANT ALL PRIVILEGES ON test_db.* TO 'test_user'@'localhost';
Query OK, 0 rows affected (0.02 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)

Cơ sở dữ liệu và người dùng thử nghiệm này có thể bị xóa bằng cách chạy:

mysql> DROP DATABASE test_db;
Query OK, 0 rows affected (0.14 sec)

mysql> DROP USER 'test_user'@'localhost';
Query OK, 0 rows affected (0.11 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> QUIT
Bye

Configure Firewall for remote connections

Để cho phép kết nối từ xa, cho phép cổng 3306 trên tường lửa

sudo firewall-cmd --add-service=mysql --permanent
sudo firewall-cmd --reload

Bạn cũng có thể giới hạn truy cập từ các mạng đáng tin cậy

sudo firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" \
service name="mysql" source address="10.1.1.0/24" accept'

Conclusion install MySQL 8.0 on Fedora 39 | Fedora 38

Cảm ơn bạn đã cài đặt MySQL 8.0 trên Fedora 39 | Fedora 38 với hướng dẫn của chúng tôi. Hẹn gặp lại vào lần tới, hãy theo dõi!