ค้นหาเว็บไซต์

วิธีติดตั้ง MySQL 8.0 บน RHEL/CentOS 8/7 และ Fedora 35


MySQL คือระบบจัดการฐานข้อมูลเชิงสัมพันธ์แบบโอเพ่นซอร์สฟรี (RDBMS) ที่เผยแพร่ภายใต้ GNU (ใบอนุญาตสาธารณะทั่วไป) . ใช้เพื่อเรียกใช้ฐานข้อมูลหลายฐานข้อมูลบนเซิร์ฟเวอร์เดียวโดยให้ผู้ใช้หลายคนเข้าถึงแต่ละฐานข้อมูลที่สร้างขึ้น

บทความนี้จะอธิบายขั้นตอนการติดตั้งและอัปเดต MySQL 8.0 เวอร์ชันล่าสุดบน RHEL/CentOS 8/7/6/ และ Fedora โดยใช้พื้นที่เก็บข้อมูล MySQL Yum ผ่านยูทิลิตี้ YUM

ขั้นตอนที่ 1: การเพิ่มพื้นที่เก็บข้อมูล MySQL Yum

1. เราจะใช้พื้นที่เก็บข้อมูลซอฟต์แวร์ MySQL Yum อย่างเป็นทางการ ซึ่งจะจัดเตรียมแพ็คเกจ RPM สำหรับการติดตั้งเวอร์ชันล่าสุดของเซิร์ฟเวอร์ MySQL, ไคลเอนต์, ยูทิลิตี้ MySQL, MySQL Workbench, ตัวเชื่อมต่อ/ ODBC และ Connector/Python สำหรับ RHEL/CentOS 8/7/6/ และ Fedora 30-35

ข้อสำคัญ: คำแนะนำเหล่านี้ใช้ได้กับการติดตั้ง MySQL ใหม่บนเซิร์ฟเวอร์เท่านั้น หากมี MySQLอยู่แล้ว > ติดตั้งโดยใช้แพ็คเกจ RPM ที่เผยแพร่โดยบุคคลที่สาม จากนั้นฉันขอแนะนำให้คุณอัปเกรดหรือแทนที่แพ็คเกจ MySQL ที่ติดตั้งโดยใช้ MySQL Yum Repository

ก่อนที่จะอัปเกรดหรือเปลี่ยนแพ็คเกจ MySQL เก่า อย่าลืมสำรองข้อมูลฐานข้อมูลและไฟล์การกำหนดค่าที่สำคัญทั้งหมดโดยใช้คู่มือการสำรองข้อมูลฐานข้อมูล MySQL ของเรา

2. ตอนนี้ให้ดาวน์โหลดและเพิ่ม พื้นที่เก็บข้อมูล MySQL Yum ต่อไปนี้ลงในรายการพื้นที่เก็บข้อมูลของระบบการแจกจ่าย Linux ของคุณเพื่อติดตั้ง MySQL เวอร์ชันล่าสุด (เช่น 8.0 เผยแพร่เมื่อ 27 กรกฎาคม 2018)

--------------- On RHEL/CentOS 8 ---------------
wget https://repo.mysql.com/mysql80-community-release-el8-1.noarch.rpm
--------------- On RHEL/CentOS 7 ---------------
wget https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
--------------- On RHEL/CentOS 6 ---------------
wget https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm
--------------- On Fedora 35 ---------------
wget https://dev.mysql.com/get/mysql80-community-release-fc35-1.noarch.rpm
--------------- On Fedora 34 ---------------
wget https://dev.mysql.com/get/mysql80-community-release-fc34-1.noarch.rpm
--------------- On Fedora 33 ---------------
wget https://dev.mysql.com/get/mysql80-community-release-fc33-1.noarch.rpm

3. หลังจากดาวน์โหลดแพ็คเกจสำหรับแพลตฟอร์ม Linux ของคุณแล้ว ให้ติดตั้งแพ็คเกจที่ดาวน์โหลดมาด้วยคำสั่งต่อไปนี้

--------------- On RHEL/CentOS 8 ---------------
yum localinstall mysql80-community-release-el8-1.noarch.rpm
--------------- On RHEL/CentOS 7 ---------------
yum localinstall mysql80-community-release-el7-1.noarch.rpm
--------------- On RHEL/CentOS 6 ---------------
yum localinstall mysql80-community-release-el6-1.noarch.rpm
--------------- On Fedora 35 ---------------
dnf localinstall mysql80-community-release-fc35-1.noarch.rpm
--------------- On Fedora 34 ---------------
dnf localinstall mysql80-community-release-fc34-1.noarch.rpm
--------------- On Fedora 33 ---------------
yum localinstall mysql80-community-release-fc33-1.noarch.rpm

คำสั่งการติดตั้งข้างต้นจะเพิ่มพื้นที่เก็บข้อมูล MySQL Yum ไปยังรายการพื้นที่เก็บข้อมูลของระบบ และดาวน์โหลดคีย์ GnuPG เพื่อตรวจสอบความสมบูรณ์ของแพ็คเกจ

4. คุณสามารถตรวจสอบได้ว่าเพิ่มพื้นที่เก็บข้อมูล MySQL Yum สำเร็จแล้วโดยใช้คำสั่งต่อไปนี้

yum repolist enabled | grep "mysql.*-community.*"
dnf repolist enabled | grep "mysql.*-community.*"      [On Fedora versions]

ขั้นตอนที่ 2: การติดตั้ง MySQL เวอร์ชันล่าสุด

5. ติดตั้ง MySQL เวอร์ชันล่าสุด (ปัจจุบันคือ 8.0) โดยใช้คำสั่งต่อไปนี้

yum install mysql-community-server
dnf install mysql-community-server      [On Fedora versions]

คำสั่งดังกล่าวจะติดตั้งแพ็คเกจที่จำเป็นทั้งหมดสำหรับเซิร์ฟเวอร์ MySQL mysql-community-server, mysql-community-client, mysql-community-common และ mysql-community-libs

ขั้นตอนที่ 3: การติดตั้งเวอร์ชันรีลีส MySQL ที่แตกต่างกัน

6. คุณยังสามารถติดตั้ง MySQL เวอร์ชันต่างๆ ได้โดยใช้พื้นที่เก็บข้อมูลย่อยที่แตกต่างกันของ MySQL Community Server พื้นที่เก็บข้อมูลย่อยสำหรับซีรีส์ MySQL ล่าสุด (ปัจจุบันคือ MySQL 8.0) ถูกเปิดใช้งานตามค่าเริ่มต้น และที่เก็บข้อมูลย่อยสำหรับเวอร์ชันอื่นๆ ทั้งหมด (เช่น ซีรีส์ MySQL 5.x) จะถูกปิดใช้งานตามค่าเริ่มต้น .

หากต้องการติดตั้งเวอร์ชันเฉพาะจากพื้นที่เก็บข้อมูลย่อย คุณสามารถใช้ตัวเลือก --enable หรือ --disable โดยใช้ yum-config-manager หรือ dnf config-manager ตามที่แสดง:

yum-config-manager --disable mysql57-community
yum-config-manager --enable mysql56-community
------------------ Fedora Versions ------------------
dnf config-manager --disable mysql57-community
dnf config-manager --enable mysql56-community

ขั้นตอนที่ 4: การเริ่มต้นเซิร์ฟเวอร์ MySQL

7. หลังจากติดตั้ง MySQL สำเร็จ ก็ถึงเวลาเริ่มต้นและเปิดใช้งานเซิร์ฟเวอร์ MySQL ด้วยคำสั่งต่อไปนี้:

service mysqld start
systemctl enable mysqld.service

คุณสามารถตรวจสอบสถานะของเซิร์ฟเวอร์ MySQL ได้โดยใช้คำสั่งต่อไปนี้

systemctl status mysqld.service
OR
service mysqld status

นี่คือผลลัพธ์ตัวอย่างการรัน MySQL ภายใต้กล่อง CentOS 7 ของฉัน

Redirecting to /bin/systemctl status  mysqld.service
mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
   Active: active (running) since Thu 2015-10-29 05:15:19 EDT; 4min 5s ago
  Process: 5314 ExecStart=/usr/sbin/mysqld --daemonize $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 5298 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 5317 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─5317 /usr/sbin/mysqld --daemonize

Oct 29 05:15:19 localhost.localdomain systemd[1]: Started MySQL Server.

8. ในที่สุดก็ตรวจสอบเวอร์ชัน MySQL ที่ติดตั้งโดยใช้คำสั่งต่อไปนี้

mysql --version

mysql  Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)

ขั้นตอนที่ 5: การรักษาความปลอดภัยการติดตั้ง MySQL

9. คำสั่ง mysql_secure_installation ช่วยให้คุณสามารถรักษาความปลอดภัยการติดตั้ง MySQL ของคุณโดยดำเนินการการตั้งค่าที่สำคัญ เช่น การตั้งรหัสผ่านรูท การลบผู้ใช้ที่ไม่ระบุชื่อ การลบการเข้าสู่ระบบรูท และอื่นๆ

หมายเหตุ: MySQL เวอร์ชัน 8.0 หรือสูงกว่าจะสร้างรหัสผ่านแบบสุ่มชั่วคราวใน /var/log/mysqld.log หลังการติดตั้ง

ใช้คำสั่งด้านล่างเพื่อดูรหัสผ่านก่อนที่จะรันคำสั่งที่ปลอดภัยของ MySQL

grep 'temporary password' /var/log/mysqld.log

เมื่อคุณทราบรหัสผ่านแล้ว คุณสามารถเรียกใช้คำสั่งต่อไปนี้เพื่อรักษาความปลอดภัยการติดตั้ง MySQL ของคุณได้

mysql_secure_installation

หมายเหตุ: ป้อนรหัสผ่านรูทใหม่หมายถึงรหัสผ่านชั่วคราวของคุณจากไฟล์ /var/log/mysqld.log

ตอนนี้ทำตามคำแนะนำบนหน้าจออย่างระมัดระวัง สำหรับการอ้างอิง โปรดดูผลลัพธ์ของคำสั่งด้านบนด้านล่าง

ผลลัพธ์ตัวอย่าง
Securing the MySQL server deployment.

Enter password for user root: Enter New Root Password

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Using existing password for root.

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

New password: Set New MySQL Password

Re-enter new password: Re-enter New MySQL Password

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

ขั้นตอนที่ 6: การเชื่อมต่อกับเซิร์ฟเวอร์ MySQL

10. เชื่อมต่อกับเซิร์ฟเวอร์ MySQL ที่ติดตั้งใหม่โดยระบุชื่อผู้ใช้และรหัสผ่าน

mysql -u root -p

ผลลัพธ์ตัวอย่าง:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, 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>

ขั้นตอนที่ 7: การอัปเดต MySQL ด้วย Yum

11. นอกจากการติดตั้งใหม่แล้ว คุณยังสามารถอัปเดตผลิตภัณฑ์และส่วนประกอบ MySQL ได้ด้วยความช่วยเหลือของคำสั่งต่อไปนี้

yum update mysql-server
dnf update mysql-server       [On Fedora versions]

เมื่อมีการอัปเดตใหม่สำหรับ MySQL ระบบจะติดตั้งการอัปเดตโดยอัตโนมัติ หากไม่เป็นเช่นนั้น คุณจะได้รับข้อความแจ้งว่า ไม่มีแพ็คเกจที่ทำเครื่องหมายไว้สำหรับการอัปเดต

เพียงเท่านี้ คุณติดตั้ง MySQL 8.0 บนระบบของคุณสำเร็จแล้ว หากคุณประสบปัญหาในการติดตั้ง โปรดใช้ส่วนความคิดเห็นของเราเพื่อรับแนวทางแก้ไข