Cài đặt MySQL 5.7 Debian 11 - Install MySQL 5.7 Debian 11

Trong bài viết này, chúng ta sẽ tìm hiểu cách install MySQL 5.7 Debian 11. MySQL là một trong những cơ sở dữ liệu quan hệ được sử dụng rộng rãi nhất. Chúng ta sẽ cài đặt phiên bản dành cho cộng đồng, đây là phần mềm miễn phí được quản lý dưới giấy phép cộng đồng chung (GPL).

Bước 1: Thêm kho lưu trữ MySQL trên Debian 11

Hãy tải xuống và cài đặt gói thiết lập kho lưu trữ mysql trên Debian 11. Chạy lệnh dưới đây:

wget https://dev.mysql.com/get/mysql-apt-config_0.8.18-1_all.deb

Khi đã tải xuống, chúng ta cần cài đặt gói kho lưu trữ.

sudo dpkg -i mysql-apt-config_0.8.18-1_all.deb

Lưu ý rằng kho lưu trữ MySQL 5.7 vẫn chưa có sẵn cho Debian 11 (Bullseye). Trong trường hợp này, chúng ta sẽ chọn Debian 10 (Buster) cho cả Debian 11.

Cài đặt MySQL 5.7 Debian 11 - Install MySQL 5.7 Debian 11

Đảm bảo rằng mysql-8.0 đã được chọn.

Cài đặt MySQL 5.7 Debian 11 - Install MySQL 5.7 Debian 11

Tiếp theo, chọn mysql-5.7 như hình dưới đây:

Cài đặt MySQL 5.7 Debian 11 - Install MySQL 5.7 Debian 11

Tiếp theo, sử dụng phím mũi tên xuống để chọn Ok sau đó nhấn Ok và gói sẽ được cài đặt.

Cài đặt MySQL 5.7 Debian 11 - Install MySQL 5.7 Debian 11

Bước 2: Install máy chủ MySQL 5.7 trên Debian 11

Do đã cài đặt kho lưu trữ cho MySQL 5.7, chúng ta sẽ tiếp tục cài đặt MySQL 5.7 trên Debian 11. Đầu tiên, cập nhật chỉ mục kho lưu trữ.

sudo apt update

Nhập các khóa GPG bị thiếu trên Debian 11

Nếu bạn gặp lỗi không thể xác minh chữ ký như dưới đây:

The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 467B942D3A79BD29

Sau đó, nhập khóa GPG bị thiếu bằng lệnh sau:

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
Executing: /tmp/apt-key-gpghome.lBFUIjtfz9/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
gpg: key 467B942D3A79BD29: public key "MySQL Release Engineering <mysql-build@oss.oracle.com>" imported
gpg: Total number processed: 1
gpg: imported: 1

Chạy lại lệnh apt update để kiểm tra xem nó hoạt động không:

sudo apt update

Cài đặt gói máy chủ MySQL 5.7 trên Debian 11

Tiếp theo, cài đặt máy chủ MySQL như sau:

sudo apt install -y mysql-community-server

Đặt mật khẩu root ưa thích của bạn khi được yêu cầu

Cài đặt MySQL 5.7 Debian 11 - Install MySQL 5.7 Debian 11

Dưới đây là mẫu kết quả thành công của quá trình cài đặt:

...
Unpacking libnuma1:amd64 (2.0.12-1+b1) ...
Selecting previously unselected package mysql-community-client.
Preparing to unpack .../mysql-community-client_5.7.37-1debian10_amd64.deb ...
Unpacking mysql-community-client (5.7.37-1debian10) ...
Selecting previously unselected package mysql-client.
Preparing to unpack .../mysql-client_5.7.37-1debian10_amd64.deb ...
Unpacking mysql-client (5.7.37-1debian10) ...
Selecting previously unselected package libmecab2:amd64.
Preparing to unpack .../libmecab2_0.996-14+b4_amd64.deb ...
Unpacking libmecab2:amd64 (0.996-14+b4) ...
Selecting previously unselected package mysql-community-server.
Preparing to unpack .../mysql-community-server_5.7.37-1debian10_amd64.deb ...
Unpacking mysql-community-server (5.7.37-1debian10) ...
Setting up libmecab2:amd64 (0.996-14+b4) ...
Setting up libnuma1:amd64 (2.0.12-1+b1) ...
Setting up mysql-community-client (5.7.37-1debian10) ...
Setting up mysql-client (5.7.37-1debian10) ...
Setting up mysql-community-server (5.7.37-1debian10) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.

Bước 3: Khởi động dịch vụ MySQL

Khi cài đặt xong, dịch vụ MySQL sẽ không được khởi động mặc định. Hãy khởi động nó và cũng kích hoạt để tự động khởi động mỗi khi máy chủ được khởi động lại.

sudo systemctl restart mysql
sudo systemctl enable mysql

Xác nhận trạng thái như dưới đây:

$ systemctl status mysql
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
Active: active (running) since Thu 2022-01-06 13:04:38 EAT; 10s ago
Main PID: 3666 (mysqld)
Tasks: 27 (limit: 2322)
Memory: 174.6M
CPU: 250ms
CGroup: /system.slice/mysql.service

Bước 4: Bảo mật MySQL 5.7 trên Debian 11

Bảo mật cài đặt MySQL DB của bạn. Vì chúng ta đã đặt mật khẩu root, bạn sẽ được yêu cầu nhập nó để tiếp tục và bạn cũng sẽ được hỏi liệu bạn có muốn thay đổi không. Phản hồi tương ứng theo ý muốn của bạn.

$ sudo mysql_secure_installation

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: 25
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

... skipping.
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: Kết nối tới máy chủ MySQL bằng cách sử dụng trình điều khiển mysql.

Tại điểm này, chúng ta đã thành công install MySQL 5.7 Debian 11. Chúng ta có thể kết nối với nó như dưới đây bằng cách sử dụng mật khẩu root đã thiết lập trước đó.

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.36 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>

Chúng ta hãy tạo một cơ sở dữ liệu thử nghiệm.

mysql> CREATE DATABASE testdb;
Query OK, 1 row affected (0.00 sec)

mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| testdb |
+--------------------+
5 rows in set (0.01 sec)

mysql>

Bạn có thể xác nhận phiên bản MySQL đã được cài đặt như dưới đây:

mysql> SHOW VARIABLES LIKE "%version%";
+-------------------------+------------------------------+
| Variable_name | Value |
+-------------------------+------------------------------+
| innodb_version | 5.7.36 |
| protocol_version | 10 |
| slave_type_conversions | |
| tls_version | TLSv1,TLSv1.1,TLSv1.2 |
| version | 5.7.36 |
| version_comment | MySQL Community Server (GPL) |
| version_compile_machine | x86_64 |
| version_compile_os | Linux |
+-------------------------+------------------------------+
8 rows in set (0.01 sec)

Bước 6: Cho phép MySQL kết nối từ xa

Nếu bạn muốn truy cập cơ sở dữ liệu MySQL từ xa, bạn có thể cho phép bằng các lệnh dưới đây:

# open MySQL port 3306 on the firewall
sudo ufw allow mysql

# allow specific addresses to connect to mysql
sudo ufw allow from 192.168.100.222 to any port 3306

Đó là tất cả về việc install MySQL 5.7 trên Debian 11. Hy vọng hướng dẫn đã hữu ích với bạn.

Mọi người cũng tìm kiếm: mysql 5.7, install mysql debian 11, debian install mysql, install mysql on debian 11, debian 11 install mysql, install mysql 5.7 debian 11, mysql server 5.7, how to install mysql on debian 11, install mysql debian.

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