Cài đặt MySQL 5.7 CentOS 7 - Install MySQL 5.7 CentOS 7

Đầu tiên, hãy nhập key GPG mới nhất của MySQL vào hệ thống.

$ sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

Bây giờ, sử dụng một trong các lệnh dưới đây để cấu hình kho lưu trữ Yum tương ứng với phiên bản hệ điều hành của bạn.

$ sudo yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

Bước 2: Cài đặt máy chủ MySQL 5.7

Sau khi bạn đã thành công trong việc bật kho lưu trữ yum MySQL trên hệ thống. Bây giờ, cài đặt MySQL 5.7 community server bằng các lệnh dưới đây tương ứng với phiên bản hệ điều hành của bạn.

$ sudo yum install mysql-community-server

Lệnh trên sẽ cài đặt MySQL community server và các phụ thuộc khác trên hệ thống của bạn. Trong quá trình cài đặt gói, mật khẩu tạm thời được tạo ra và ghi vào tệp nhật ký của MySQL.

Sau khi cài đặt RPM, sử dụng lệnh sau để khởi động dịch vụ MySQL.

$ sudo systemctl start mysqld

Trong lần khởi động đầu tiên, MySQL lưu trữ mật khẩu tài khoản root trong tệp nhật ký, có thể tìm thấy bằng lệnh sau.

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

Đầu ra mẫu:

2017-03-30T02:57:10.981502Z 1 [Note] A temporary password is generated for root@localhost: Nm(!pKkkjo68e

Bước 4: Cấu hình ban đầu cho MySQL

Chạy kịch bản mysql_secure_installation và tuân theo hướng dẫn. Nó sẽ yêu cầu mật khẩu root. Sử dụng mật khẩu root tạm thời đã nhận được trong bước trước đó.

$ /usr/bin/mysql_secure_installation

Hướng dẫn này sẽ yêu cầu bạn nhập thông tin. Hãy nhập một mật khẩu root mới mạnh cho tài khoản MySQL root. Đối với các tùy chọn còn lại, đọc tùy chọn và cung cấp thông tin như yêu cầu. Bạn nên nhấn 'y' cho tất cả để tài khoản được bảo mật tốt hơn.

Securing the MySQL server deployment.

Enter password for user root: **********

The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

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

New password: ******************

Re-enter new 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!

Bước 5: Đăng nhập vào MySQL

Bạn đã thành công trong việc install MySQL 5.7 CentOS 7. Hãy đăng nhập vào MySQL bằng quyền truy cập root và thử tạo một cơ sở dữ liệu thử nghiệm. Sử dụng mật khẩu bạn đã gán ở bước 4.

$ mysql -u root -p

Đầu ra:

Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.38 MySQL Community Server (GPL)

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

Sau khi đăng nhập vào máy chủ MySQL, hãy tạo một cơ sở dữ liệu và tài khoản người dùng bằng các lệnh sau đây.

/* CREATE NEW DATABASE */
mysql> CREATE DATABASE mydb;

/* CREATE MYSQL USER FOR DATABASE */
mysql> CREATE USER 'db_user'@'localhost' IDENTIFIED BY 'password';

/* GRANT Permission to User on Database */
mysql> GRANT ALL ON mydb.* TO 'db_user'@'localhost';

/* RELOAD PRIVILEGES */
mysql> FLUSH PRIVILEGES;

Bước 6: Kiểm tra phiên bản MySQL

Xác minh phiên bản MySQL đã được cài đặt trên hệ thống của bạn. Lệnh sau sẽ hiển thị phiên bản MySQL đã cài đặt.

$ mysql -V

Đầu ra:

mysql Ver 14.14 Distrib 5.7.38, for Linux (x86_64) using EditLine wrapper

Trong hướng dẫn này, bạn đã học cách cài đặt MySQL 5.7 trên các hệ thống CentOS 7.

Mọi người cùng tìm kiếm: install mysql centos 7, mysql 5.7, install mysql on centos 7, install mysql 5.7 centos 7, centos install mysql, install mysql server centos 7, centos 7 install mysql, install mysql 5.7 on centos 7, mysql57-community-release-el7-11.noarch.rpm, mysql 5.7 centos 7

Các gói dịch vụ Cloud VPS của KDATA mang đến cho bạn nhiều lựa chọn về hiệu suất cũng như khả năng lưu trữ, mọi nhu cầu về doanh nghiệp đều được đáp ứng. KDATA đảm bảo khả năng uptime lên đến 99,99%, toàn quyền quản trị và free backup hằng ngày. Tham khảo ngay các gói dịch vụ Cloud VPS:

https://kdata.vn/cloud-vps

👉 Liên hệ ngay KDATA hỗ trợ tận tình, support tối đa, giúp bạn trải nghiệm dịch vụ giá hời chất lượng tốt nhất