Cài đặt máy chủ mysql lên ubuntu

Trong hệ sinh thái dữ liệu lớn hiện đại, MySQL là một trong những công nghệ nổi tiếng nhất. Nó cũng được coi là một cơ sở dữ liệu phổ biến và hiệu quả trên nhiều ngành công nghiệp. Để làm chủ hệ quản trị cơ sở dữ liệu này chỉ cần có hiểu biết cơ bản. Ngay cả khi bạn không quen với các hệ thống quan hệ, bạn có thể tạo các hệ thống lưu trữ an toàn, nhanh chóng và mạnh mẽ với MySQL

Bài viết này sẽ thảo luận về quy trình cài đặt MySQL trên Ubuntu 22. 04. Vì vậy, hãy bắt đầu

Cách cài đặt MySQL trên Ubuntu 22. 04

Để cài đặt MySQL trên Ubuntu 22. 04, trước tiên, thực hiện các kho lưu trữ hệ thống và sau đó thực hiện lệnh “sudo apt-get install mysql-server”. Sau đó, định cấu hình nó trên hệ thống của bạn bằng lệnh “sudo mysql_secure_installation”. Sử dụng hướng dẫn cấu hình, bạn có thể đặt cấp chính sách xác thực mật khẩu, xóa cơ sở dữ liệu thử nghiệm và quyền truy cập của nó, đồng thời tải lại các đặc quyền. Bài viết này đã thảo luận về phương pháp cài đặt MySQL trên Ubuntu 22. 04

Người dùng Ubuntu có thể lựa chọn giữa hai Hệ thống quản lý cơ sở dữ liệu quan hệ (RDBMS) đáng tin cậy, MySQL và MariaDB. MySQL có một lợi thế lâu dài về mức độ phổ biến, nhưng MariaDB ngày càng được quan tâm nhiều hơn do các lợi thế về hiệu suất và các tính năng bổ sung của nó. Hướng dẫn này so sánh hai hệ thống cơ sở dữ liệu và cung cấp hướng dẫn về cách cài đặt và sử dụng MySQL trên Ubuntu 20. 04

MySQL là gì?

MySQL RDBMS là một trong những ứng dụng nguồn mở phổ biến nhất. Nó là một phần của LAMP Stack, nền tảng của nhiều hệ thống Ubuntu. Ngăn xếp này bao gồm Linux, máy chủ web Apache, MySQL RDBMS và ngôn ngữ lập trình PHP. Các ứng dụng này hoạt động cùng nhau để hỗ trợ các ứng dụng web, phát triển phần mềm và các hoạt động chuyên biệt như khoa học dữ liệu. Công dụng chính của MySQL là trong các cấu hình máy chủ đơn vừa và nhỏ

Truy vấn MySQL được viết bằng Ngôn ngữ truy vấn có cấu trúc (SQL). Là một cơ sở dữ liệu quan hệ, nó lưu trữ và tổ chức dữ liệu trong các bảng. Bảng cấu trúc dữ liệu thực tế bên trong bảng dưới dạng một chuỗi các hàng, với mỗi hàng bao gồm một hoặc nhiều cột. Mỗi hàng đại diện cho một mục nhập khác nhau trong bảng, trong khi mỗi cột chứa một trường dữ liệu trong mục nhập đó. Các trường dữ liệu trong các bảng này có thể liên quan đến nhau và các mối quan hệ này giúp cấu trúc và tổ chức cơ sở dữ liệu. Các câu lệnh SQL chuyên dụng cho phép khách hàng thêm, xóa, sửa đổi và truy xuất dữ liệu

MySQL được biết đến với tính ổn định và đáng tin cậy, đồng thời được coi là đơn giản và dễ sử dụng. Nó có sẵn dưới dạng phần mềm mã nguồn mở miễn phí theo Giấy phép Công cộng GNU. MySQL có sẵn cho tất cả các bản phân phối Linux cũng như các hệ điều hành khác. Nó hiện thuộc sở hữu của Tập đoàn Oracle. Oracle cũng cung cấp MySQL Enterprise Edition thương mại như một sản phẩm cao cấp hơn

MySQL so với. MariaDB

Hai lựa chọn thay thế cơ sở dữ liệu nguồn mở chính, MySQL và MariaDB, rất giống nhau. Cả hai đều là sản phẩm RDBMS và cả hai đều sử dụng SQL. Cả hai hệ thống cơ sở dữ liệu đều có phiên bản miễn phí, chúng trông và hoạt động theo cùng một cách. Bởi vì MariaDB ban đầu được phân nhánh từ MySQL, điều này không có gì đáng ngạc nhiên. MariaDB kể từ đó đã trải qua quá trình phát triển hơn nữa và có nhiều cải tiến mới về bảo mật và hiệu suất. Tuy nhiên, với MySQL, nhiều tính năng nâng cao chỉ có trong Phiên bản doanh nghiệp. Dưới đây là tổng hợp những điểm giống và khác nhau giữa hai sản phẩm

  • MariaDB hỗ trợ nhiều kết nối hơn MySQL
  • Cả hai cơ sở dữ liệu đều có thể hoạt động với nhiều hệ thống lưu trữ, mặc dù MariaDB cung cấp nhiều tùy chọn hơn
  • MariaDB có thể sao chép dữ liệu nhanh hơn MySQL và có hiệu suất tổng thể tốt hơn. MySQL xử lý các giao dịch lớn hiệu quả hơn, nhưng MariaDB hoạt động tốt hơn trong các tình huống mở rộng
  • MySQL hỗ trợ một số tính năng mà MariaDB không có, chẳng hạn như các cột động. Mỗi cơ sở dữ liệu có một vài tính năng và cải tiến nâng cao mà cơ sở dữ liệu kia không có
  • MySQL cũ hơn, được thiết lập tốt hơn, phổ biến hơn và có nhiều hỗ trợ cộng đồng hơn. MySQL cung cấp các gói hỗ trợ trả phí toàn diện hơn
  • MariaDB và MySQL hoàn toàn tương thích
  • Cả hai sản phẩm đều là nguồn mở, nhưng mô hình cấp phép MySQL hạn chế hơn

Tóm lại, cả hai hệ thống đều quá đủ cho hầu hết người dùng. MariaDB có hiệu suất tốt hơn, trong khi MySQL được thiết lập tốt hơn và được hỗ trợ tốt hơn

Trước khi bắt đầu

Ghi chú

Các bước trong hướng dẫn này được viết cho người dùng không root. Các lệnh yêu cầu đặc quyền nâng cao có tiền tố là

VALIDATE PASSWORD COMPONENT 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 component?
    
8. Nếu bạn không quen với lệnh
VALIDATE PASSWORD COMPONENT 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 component?
    
8, hãy xem hướng dẫn Người dùng và Nhóm Linux

Cách cài đặt máy chủ MySQL

MySQL có sẵn như là một phần của các gói Ubuntu mặc định, vì vậy không cần thiết phải chỉnh sửa danh sách nguồn. Nó có thể được cài đặt dễ dàng bằng cách sử dụng

Please set the password for root here.

New password:

Re-enter new password:
0, nhưng điều quan trọng là phải bảo mật ứng dụng và chỉnh sửa tường lửa sau đó. Các hướng dẫn này hướng đến người dùng Ubuntu, nhưng thường áp dụng cho những người muốn cài đặt MySQL trên một bản phân phối Linux khác

Tải xuống MySQL

Để cài đặt máy chủ MySQL trên Ubuntu, hãy làm theo các bước dưới đây

  1. Cài đặt ứng dụng máy chủ MySQL

    sudo apt install mysql-server
    
  2. Xác nhận máy chủ MySQL đang chạy bằng lệnh

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    1. Nó sẽ hiển thị trạng thái của
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    2

    sudo systemctl status mysql
    
    mysql.service - MySQL Community Server
        Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
        Active: active (running) since Thu 2021-09-09 12:24:29 UTC; 1h 44min ago
        

Cấu hình máy chủ MySQL trên Linux

Tiện ích

Please set the password for root here.

New password:

Re-enter new password:
3 là cách dễ nhất để cấu hình ứng dụng. Để sử dụng tập lệnh thiết lập, hãy làm theo các bước sau

  1. Khởi chạy tiện ích

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    3 để đặt mật khẩu gốc và định cấu hình các tùy chọn mặc định khác

    VALIDATE PASSWORD COMPONENT 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 component?
        
    0
  2. Ứng dụng hỏi có bật thành phần

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    5 không. Nếu bạn trả lời
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    6, nó sẽ hỏi bạn có đặt độ mạnh mật khẩu thành
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    7,
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    8 hay
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    9 hay không

    VALIDATE PASSWORD COMPONENT 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 component?
        
  3. Tại dấu nhắc tiếp theo, tiện ích yêu cầu nhập mật khẩu cho tài khoản root. Đặt mật khẩu rồi nhập lại

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
  4. Các câu hỏi sau hỏi liệu có xóa người dùng ẩn danh hay không, cho phép tài khoản

    VALIDATE PASSWORD COMPONENT 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 component?
        
    80 kết nối từ xa và xóa cơ sở dữ liệu
    VALIDATE PASSWORD COMPONENT 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 component?
        
    81. Nhập
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    6 hoặc
    VALIDATE PASSWORD COMPONENT 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 component?
        
    83 tại mỗi dấu nhắc tùy theo sở thích của bạn. Cơ sở dữ liệu
    VALIDATE PASSWORD COMPONENT 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 component?
        
    81 rất hữu ích trong quá trình xác thực ban đầu, nhưng vì lý do bảo mật, tốt nhất là không cho phép tài khoản
    VALIDATE PASSWORD COMPONENT 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 component?
        
    80 đăng nhập từ xa

    VALIDATE PASSWORD COMPONENT 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 component?
        
    8
  5. Khi được nhắc, hãy tải lại các bảng

    VALIDATE PASSWORD COMPONENT 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 component?
        
    86 để cập nhật cơ sở dữ liệu

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    6
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    7____28
  6. (Tùy chọn) Để truy cập MySQL từ xa, hãy đảm bảo rằng lưu lượng truy cập MySQL được cho phép thông qua tường lửa

    VALIDATE PASSWORD COMPONENT 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 component?
        
    87. Thêm quy tắc sau để mở cổng
    VALIDATE PASSWORD COMPONENT 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 component?
        
    88 trên tường lửa. Không nên thêm quy tắc này nếu không cần truy cập từ xa

    sudo systemctl status mysql
    
    0
    sudo systemctl status mysql
    
    1

Đăng nhập vào MySQL với tư cách Người dùng gốc

Mặc dù người dùng

VALIDATE PASSWORD COMPONENT 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 component?
    
80 có toàn quyền truy cập vào cơ sở dữ liệu MySQL, nhưng việc sử dụng nó nên được dành riêng cho mục đích quản trị. Điều này làm giảm khả năng vô tình ghi đè lên các phần quan trọng của cơ sở dữ liệu. Ngay cả trong thiết lập một người dùng, nên tạo một tài khoản người dùng riêng cho hầu hết các hoạt động của MySQL

Để truy cập máy chủ MySQL với tư cách là người dùng

VALIDATE PASSWORD COMPONENT 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 component?
    
80 và tạo tài khoản người dùng mới, hãy làm theo các bước sau

  1. Sử dụng lệnh

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    61 để truy cập cơ sở dữ liệu. MySQL xác thực người dùng root dựa trên thông tin đăng nhập gốc của họ khi đăng nhập cục bộ, do đó không cần mật khẩu. Ngoài ra, truy cập tài khoản gốc bằng cách sử dụng
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    62, cùng với mật khẩu
    VALIDATE PASSWORD COMPONENT 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 component?
        
    80

    sudo systemctl status mysql
    
    2
  2. MySQL hiển thị số phát hành và một số thông tin về cài đặt, sau đó hiển thị dấu nhắc MySQL

    sudo systemctl status mysql
    
    3
  3. Để xác nhận MySQL đang hoạt động chính xác, hãy sử dụng lệnh

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    64 để hiển thị tất cả các cơ sở dữ liệu

    sudo systemctl status mysql
    
    4
    sudo systemctl status mysql
    
    5
  4. Tạo người dùng mới bằng lệnh

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    65. Nhập tên người dùng ở định dạng
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    66, trong đó
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    67 là địa chỉ IP của người dùng. Nếu người dùng đang truy cập MySQL từ Linode cục bộ, hãy thay thế
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    68 thay cho Địa chỉ IP. Trong lệnh bên dưới, thay thế
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    69 và
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    70 bằng tên người dùng và mật khẩu thực tế

    Ghi chú

    MySQL cung cấp một số cơ chế xác thực khác nhau. Phương pháp

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    71 được khuyến nghị cho những người dùng muốn đăng nhập bằng mật khẩu và được sử dụng tại đây. Tuy nhiên, một số ứng dụng cũ hơn có thể không xác thực đúng theo cách này. Trong trường hợp đó, nên sử dụng
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    72 để thay thế. Bản sao nguồn-bản sao của MySQL có thể yêu cầu phương thức
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    73

    sudo systemctl status mysql
    
    6
  5. Cấp quyền truy cập cho người dùng mới bằng lệnh

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    74, sử dụng định dạng
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    75. Một số đặc quyền phổ biến hơn bao gồm
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    76,
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    77,
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    78,
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    79,
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    80,
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    81 và
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    82. Để áp dụng các đặc quyền này cho tất cả các cơ sở dữ liệu, hãy sử dụng biến ký tự đại diện
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    83. Lệnh sau cấp các đặc quyền phi quản trị chung trên tất cả các cơ sở dữ liệu cho
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    69

    sudo systemctl status mysql
    
    7
  6. Để thoát khỏi dấu nhắc MySQL, hãy nhập

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    85

    sudo systemctl status mysql
    
    8

Cách sử dụng MySQL

MySQL sử dụng cú pháp SQL tiêu chuẩn cho tất cả các lệnh của nó. Các bước trong phần này trình bày cách thực hiện các tác vụ cơ bản trong MySQL, chẳng hạn như tạo cơ sở dữ liệu, bảng và thêm dữ liệu. Để biết thông tin đầy đủ về cách sử dụng MySQL, hãy xem MySQL Reference Manual. Để có phần giới thiệu ngắn gọn nhưng kỹ lưỡng, hãy thử hướng dẫn về MySQL

Tạo cơ sở dữ liệu

  1. Để tạo cơ sở dữ liệu, hãy đăng nhập vào MySQL bằng tài khoản có đặc quyền

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    76. Thay thế
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    87 bằng tên người dùng bạn đã tạo

    sudo systemctl status mysql
    
    9
  2. Tạo cơ sở dữ liệu mới bằng lệnh

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    88. Thay thế
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    89 bằng tên mong muốn cho cơ sở dữ liệu của bạn

    mysql.service - MySQL Community Server
        Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
        Active: active (running) since Thu 2021-09-09 12:24:29 UTC; 1h 44min ago
        
    0
    mysql.service - MySQL Community Server
        Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
        Active: active (running) since Thu 2021-09-09 12:24:29 UTC; 1h 44min ago
        
    1
  3. Để xác nhận cơ sở dữ liệu mới đã được tạo chính xác, hãy sử dụng

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    64

    sudo systemctl status mysql
    
    4
    mysql.service - MySQL Community Server
        Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
        Active: active (running) since Thu 2021-09-09 12:24:29 UTC; 1h 44min ago
        
    3
  4. Cho biết cơ sở dữ liệu mà bạn muốn làm việc bằng cách sử dụng lệnh

    sudo systemctl status mysql
    
    01. Thay thế
    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    89 bằng tên cơ sở dữ liệu mà bạn vừa tạo

    mysql.service - MySQL Community Server
        Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
        Active: active (running) since Thu 2021-09-09 12:24:29 UTC; 1h 44min ago
        
    4
    mysql.service - MySQL Community Server
        Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
        Active: active (running) since Thu 2021-09-09 12:24:29 UTC; 1h 44min ago
        
    5
    Ghi chú

    Bạn cũng có thể sử dụng lệnh

    sudo systemctl status mysql
    
    01 khi có nhiều hơn một cơ sở dữ liệu và bạn muốn chuyển đổi giữa chúng

  5. Để tìm ra tên của cơ sở dữ liệu hiện tại, hãy sử dụng lệnh

    sudo systemctl status mysql
    
    04. Đầu ra hiển thị tên cơ sở dữ liệu

    mysql.service - MySQL Community Server
        Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
        Active: active (running) since Thu 2021-09-09 12:24:29 UTC; 1h 44min ago
        
    6
    mysql.service - MySQL Community Server
        Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
        Active: active (running) since Thu 2021-09-09 12:24:29 UTC; 1h 44min ago
        
    7

Tạo một bảng

Tại thời điểm này, cơ sở dữ liệu,

Please set the password for root here.

New password:

Re-enter new password:
89 không có bất kỳ bảng nào, vì vậy không thể lưu trữ bất kỳ dữ liệu nào trong đó. Để xác định một bảng, hãy sử dụng lệnh
sudo systemctl status mysql
06. Cùng với tên của bảng, lệnh này yêu cầu tên và kiểu dữ liệu của từng trường. Kiểu dữ liệu đặc trưng cho dữ liệu được lưu trữ trong trường. Ví dụ: kiểu dữ liệu có thể là một chuỗi có độ dài thay đổi, được gọi là
sudo systemctl status mysql
07. Để biết danh sách đầy đủ các loại dữ liệu, hãy tham khảo tài liệu về MySQL. Một số kiểu dữ liệu phổ biến hơn như sau

  • INT. Điều này có thể chứa một giá trị giữa
    sudo systemctl status mysql
    
    08 và
    sudo systemctl status mysql
    
    09. Nếu được chỉ định là
    sudo systemctl status mysql
    
    10, nó có thể lưu trữ các giá trị giữa
    sudo systemctl status mysql
    
    11 và
    sudo systemctl status mysql
    
    12
  • NHỎ. Giữ một giá trị số nguyên thậm chí còn nhỏ hơn giữa
    sudo systemctl status mysql
    
    13 và
    sudo systemctl status mysql
    
    14
  • TRÔI NỔI. Loại này có thể lưu trữ một số dấu phẩy động
  • NGÀY. Lưu trữ một ngày ở định dạng
    sudo systemctl status mysql
    
    15
  • NGÀY GIỜ. Lưu trữ kết hợp ngày và giờ ở định dạng
    sudo systemctl status mysql
    
    16. Đồng thời có thể được lưu trữ mà không có dấu gạch ngang và dấu hai chấm ở định dạng
    sudo systemctl status mysql
    
    17
  • VARCHAR(N). Đây là một chuỗi có độ dài thay đổi từ
    sudo systemctl status mysql
    
    18 đến
    sudo systemctl status mysql
    
    19 ký tự, với độ dài tối đa là
    sudo systemctl status mysql
    
    20 ký tự
  • CHỮ. Loại dữ liệu này chứa tối đa
    sudo systemctl status mysql
    
    21 ký tự. Nó có thể chứa văn bản, hình ảnh hoặc dữ liệu nhị phân
  • CHAR(N). Loại này đại diện cho trường văn bản có độ dài cố định có độ dài
    sudo systemctl status mysql
    
    19. Ví dụ: để giữ mã trạng thái gồm hai ký tự, hãy sử dụng loại dữ liệu là
    sudo systemctl status mysql
    
    23

Trước khi tạo bất kỳ bảng nào, điều quan trọng là phải quyết định lược đồ cho cơ sở dữ liệu. Lược đồ mô tả mỗi bảng đại diện cho cái gì, dữ liệu nào được lưu trữ trong mỗi bảng và các bảng liên quan với nhau như thế nào. Để tạo một bảng, hãy làm theo các bước sau

  1. Trong khi đăng nhập vào MySQL, hãy chuyển sang cơ sở dữ liệu nơi bạn muốn thêm bảng

    mysql.service - MySQL Community Server
        Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
        Active: active (running) since Thu 2021-09-09 12:24:29 UTC; 1h 44min ago
        
    8
  2. Sử dụng lệnh

    sudo systemctl status mysql
    
    06 để tạo bảng mới. Sử dụng định dạng
    sudo systemctl status mysql
    
    25

    mysql.service - MySQL Community Server
        Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
        Active: active (running) since Thu 2021-09-09 12:24:29 UTC; 1h 44min ago
        
    9
    VALIDATE PASSWORD COMPONENT 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 component?
        
    00
  3. Để xác nhận bảng hiện đã tồn tại, hãy sử dụng lệnh

    sudo systemctl status mysql
    
    26

    VALIDATE PASSWORD COMPONENT 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 component?
        
    01
    VALIDATE PASSWORD COMPONENT 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 component?
        
    02
  4. Để xem lại cấu trúc bảng và xác minh danh sách các trường, hãy sử dụng lệnh

    sudo systemctl status mysql
    
    27

    VALIDATE PASSWORD COMPONENT 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 component?
        
    03
    VALIDATE PASSWORD COMPONENT 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 component?
        
    04
  5. Nếu một bảng không còn cần thiết, hãy xóa nó bằng lệnh

    sudo systemctl status mysql
    
    28

    thận trọng

    Khi một bảng bị hủy, tất cả dữ liệu bên trong bảng sẽ bị mất và không thể khôi phục được

    VALIDATE PASSWORD COMPONENT 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 component?
        
    05

Thêm và truy xuất dữ liệu

Cách chính để chèn một hàng dữ liệu mới vào bảng là sử dụng lệnh

Please set the password for root here.

New password:

Re-enter new password:
79

  1. Để thêm một hàng, hãy sử dụng lệnh

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    79. Chỉ định tên bảng, từ khóa
    sudo systemctl status mysql
    
    31 và danh sách các giá trị được phân tách bằng dấu phẩy trong dấu ngoặc vuông ở định dạng
    sudo systemctl status mysql
    
    32. Các giá trị cột phải có cùng trình tự như định nghĩa bảng, với các giá trị chuỗi và ngày trong dấu ngoặc kép. Ví dụ: để thêm dữ liệu vào
    sudo systemctl status mysql
    
    33, hãy chỉ định các giá trị cho
    sudo systemctl status mysql
    
    34,
    sudo systemctl status mysql
    
    35,
    sudo systemctl status mysql
    
    36 và
    sudo systemctl status mysql
    
    37 theo thứ tự đó

    VALIDATE PASSWORD COMPONENT 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 component?
        
    06
    VALIDATE PASSWORD COMPONENT 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 component?
        
    07
  2. Để truy xuất dữ liệu, hãy sử dụng lệnh

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    82, cùng với một số ràng buộc cho MySQL biết hàng nào sẽ trả về. Toàn bộ nội dung của bảng có thể được trả về hoặc chỉ một tập hợp con. Để chọn tất cả các hàng trong một bảng, hãy sử dụng lệnh
    sudo systemctl status mysql
    
    39, nhưng không thêm bất kỳ từ hạn định nào

    VALIDATE PASSWORD COMPONENT 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 component?
        
    08
    VALIDATE PASSWORD COMPONENT 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 component?
        
    09
  3. Cũng có thể chỉ chọn các hàng phù hợp với tiêu chí cụ thể, chẳng hạn như cột được đặt thành một giá trị nhất định. Sử dụng từ khóa

    sudo systemctl status mysql
    
    40 làm hạn định, theo sau là tiêu chí đối sánh làm ràng buộc. Trong ví dụ này, chỉ những hàng trong đó
    sudo systemctl status mysql
    
    35 được đặt thành
    sudo systemctl status mysql
    
    42 mới được hiển thị

    VALIDATE PASSWORD COMPONENT 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 component?
        
    0
    VALIDATE PASSWORD COMPONENT 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 component?
        
    1
  4. Đối với các bảng có nhiều cột, việc giới hạn thông tin được hiển thị thường dễ dàng hơn. Để chỉ chọn một số cột nhất định cho mỗi hàng, hãy chỉ định tên cột thay vì ký hiệu

    sudo systemctl status mysql
    
    43

    VALIDATE PASSWORD COMPONENT 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 component?
        
    2____03
  5. Để sửa đổi một hàng trong bảng, hãy sử dụng lệnh

    Please set the password for root here.
    
    New password:
    
    Re-enter new password:
    80. Từ khóa
    sudo systemctl status mysql
    
    45 cho biết cột cần cập nhật và giá trị mới. Nếu cần, từ khóa
    sudo systemctl status mysql
    
    40 cung cấp phương pháp hạn chế thao tác chỉ áp dụng cho một số hàng nhất định. Trong ví dụ sau, giá trị của
    sudo systemctl status mysql
    
    37 chỉ được thay đổi thành
    sudo systemctl status mysql
    
    48 nếu
    sudo systemctl status mysql
    
    35 bằng với
    sudo systemctl status mysql
    
    42

    VALIDATE PASSWORD COMPONENT 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 component?
        
    4
    VALIDATE PASSWORD COMPONENT 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 component?
        
    5
  6. Câu lệnh

    sudo systemctl status mysql
    
    39 có thể được sử dụng để xác nhận cập nhật

    VALIDATE PASSWORD COMPONENT 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 component?
        
    08
    VALIDATE PASSWORD COMPONENT 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 component?
        
    7

Sự kết luận. MySQL trên Ubuntu 20. 04

MySQL là một lựa chọn tốt cho các ứng dụng web vừa và nhỏ. Nó sử dụng ngôn ngữ lập trình SQL tiêu chuẩn công nghiệp, khá dễ sử dụng. MySQL rất ổn định và mạnh mẽ và có nhiều tài nguyên cùng với sự hỗ trợ tốt. Giải pháp thay thế chính cho MySQL là MariaDB. Nó có hiệu suất tốt hơn và các tính năng mới hơn, nhưng không được thiết lập tốt

Bạn có thể dễ dàng tải xuống và cài đặt máy chủ MySQL trên Ubuntu bằng các gói

Please set the password for root here.

New password:

Re-enter new password:
0 và tiện ích
Please set the password for root here.

New password:

Re-enter new password:
3. Ngay cả khi bạn là người duy nhất đang sử dụng MySQL, tốt nhất bạn nên tạo một người dùng MySQL mới với các đặc quyền hạn chế hơn

Để sử dụng MySQL, trước tiên hãy xác định lược đồ cơ sở dữ liệu và xác định nội dung bảng. Tiếp theo, tạo cơ sở dữ liệu và các bảng dữ liệu. Có thể thêm dữ liệu bằng lệnh

Please set the password for root here.

New password:

Re-enter new password:
79, sửa đổi bằng lệnh
Please set the password for root here.

New password:

Re-enter new password:
80 và truy xuất bằng lệnh
Please set the password for root here.

New password:

Re-enter new password:
82. Tất nhiên, MySQL có thể thực hiện các hoạt động thậm chí rất phức tạp. Xem qua hướng dẫn về MySQL để bắt đầu và tham khảo tài liệu về MySQL để có cái nhìn tổng quan đầy đủ

Thêm thông tin

Bạn có thể muốn tham khảo các tài nguyên sau để biết thêm thông tin về chủ đề này. Mặc dù chúng được cung cấp với hy vọng rằng chúng sẽ hữu ích, xin lưu ý rằng chúng tôi không thể đảm bảo tính chính xác hoặc kịp thời của các tài liệu được lưu trữ bên ngoài

Làm cách nào để cài đặt máy chủ MySQL trong Linux từng bước?

Đối với hầu hết mọi hệ thống Linux, các lệnh sau được sử dụng để cài đặt MySQL. .
Bước 1. Chuyển đến thiết bị đầu cuối bằng Ctrl + Alt + T. .
Bước 2. Nhấn “y” để tiếp tục
Bước 3. Để xác minh cài đặt hoặc để biết phiên bản, hãy nhập các lệnh sau trong Terminal của bạn
Bước 4. Bây giờ chúng ta sẽ thiết lập thành phần MẬT KHẨU HỢP LỆ

Ubuntu có đi kèm với MySQL không?

Kho gói APT của Ubuntu bao gồm gói MySQL theo mặc định , thuận tiện cho việc cài đặt MySQL Ubuntu trong một lệnh duy nhất. GHI CHÚ. Kho lưu trữ APT mặc định của Ubuntu có thể không phải lúc nào cũng có phiên bản MySQL mới nhất.

Cách cài đặt MySQL trong Ubuntu 18. 04 sử dụng thiết bị đầu cuối hỏi Ubuntu?

Cách cài đặt MySQL trong Ubuntu 18. 04 sử dụng thiết bị đầu cuối hỏi Ubuntu? .
Bước 1. Kích hoạt kho lưu trữ MySQL
Bước 2. Cài đặt kho lưu trữ MySQL
Bước 3. Làm mới kho lưu trữ
Bước 4. Cài đặt MySQL
Bước 5. Thiết lập Bảo mật MySQL
Bước 6. Bắt đầu, Dừng hoặc Kiểm tra Trạng thái của Dịch vụ MySQL
Bước 7. Khởi chạy MySQL để nhập lệnh

Làm cách nào để cài đặt MySQL APT?

Cài đặt MySQL với APT. Cài đặt MySQL bằng lệnh sau. $> sudo apt-get cài đặt máy chủ mysql. .
Bắt đầu và dừng máy chủ MySQL. Máy chủ MySQL được khởi động tự động sau khi cài đặt