Mysql mariadb phiên bản mới nhất

Tài liệu hướng dẫn cài đặt MySQL, MariaDB để thực thi SQL. Do vậy, các báo cáo chỉ đủ các bước để bạn có thể sử dụng MySQl hoặc MariaDB để thực hiện các hành động về SQL nói chung

1. Cài đặt MySQL 5. x trên CentOS 7

  • Thực hiện cập nhật OS và cài đặt các gói phần mềm bổ sung

    yum update -y 
    
    yum install -y epel-release
    
    yum install -y wget byobu yum-utils git  
    

  • Khai báo repos của MySQL cho CentOS

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    

  • Cài đặt MySQL

    sudo yum install -y mysql-server
    

  • Khởi động MySQL

    sudo systemctl start mysqld
    sudo systemctl enable mysqld
    

  • Kiểm tra phiên bản của MySQL

    mysql -V
    

  • Ta sẽ có kết quả

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

  • Mở tường lửa để cho phép các máy ở xa kết nối với MySQL

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

Thực hiện khai báo mật khẩu lần đầu tiên cho MySQL

Run command has been a valid

firewall-cmd --add-service=mysql --permanent
firewall-cmd --reload
2 to setting password lần đầu tiên đăng nhập đối với MySQL. Ta sẽ làm theo hướng dẫn

  • Tại dòng

    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    3 nhấn
    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    4 (mật khẩu trống) để chuyển sang bước tiếp theo vì ngay từ đầu MySQL không có mật khẩu để truy cập

  • Tại dòng

    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    5 lựa chọn
    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    6 để bắt đầu nhập mật khẩu cho tài khoản
    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    7 của MySQL

  • Tài dòng

    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    8 và
    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    9 tiến trình nhập mật khẩu. Please write this password to use for the next step. Sau khi thực hiện ta sẽ có kết quả như bên dưới là thành công

    Password updated successfully!
    Reloading privilege tables..
    .. Success!
    

  • Tại dòng

    Password updated successfully!
    Reloading privilege tables..
    .. Success!
    
    0 lựa chọn phím
    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    6 để xóa tài khoản vô danh được cung cấp mặc định ngay khi cài đặt MySQL

  • Tại dòng

    Password updated successfully!
    Reloading privilege tables..
    .. Success!
    
    2 lựa chọn phím
    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    6 để vô hiệu hóa tính năng cho phép truy cập MySQL với tài khoản
    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    7 từ xa (Từ các máy khác thông qua công cụ hoặc máy khách mysql)

  • Tại dòng

    Password updated successfully!
    Reloading privilege tables..
    .. Success!
    
    5 lựa chọn
    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    6 để xóa cơ sở dữ liệu có tên là
    Password updated successfully!
    Reloading privilege tables..
    .. Success!
    
    7 được sinh ra từ lệnh cấm đâu

  • Tại dòng

    Password updated successfully!
    Reloading privilege tables..
    .. Success!
    
    8 lựa chọn
    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    6 để khởi động lại MySQL nhằm áp dụng các cấu hình ở các bước trên xuống. Kết quả màn hình sẽ là

    All done!  If you've completed all of the above steps, your MySQL
    installation should now be secure.
    
    Thanks for using MySQL!
    
    Cleaning up...
    

  • Sau khi thiết lập xong, hãy thực hiện đăng nhập vào MySQL thông qua lệnh

    All done!  If you've completed all of the above steps, your MySQL
    installation should now be secure.
    
    Thanks for using MySQL!
    
    Cleaning up...
    
    0

    [root@c7srv02 ~]# mysql -u root -p
    Enter password:
    

Ở màn hình trên, nhập mật khẩu vừa thiết lập lúc trước để sử dụng

  • Nếu nhập đúng mật khẩu, ta sẽ có kết quả thông báo như bên dưới và bắt đầu ở chế độ làm việc với MySQL

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    
    0

  • Thực hiện truy vấn sql cơ bản

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    
    1

Tới đây, bạn đã có thể truy cập trực tiếp vào MySQL trên máy đó. Đối với trường hợp bạn cần sử dụng các công cụ như.

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Cleaning up...
1 hoặc kết nối tới MySQL từ một máy khác thì bạn cần phân quyền công việc này. Lưu ý, việc phân quyền này cần thận trọng và hạn chế khi thực hiện ở các hệ thống thực vì lý do bảo mật

  • Thực hiện phân quyền cho tài khoản
    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    7 của MySQL để có thể đăng nhập từ hệ thống khác

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    
    2

2. Cài đặt MariaDB 10. x trên CentOS 7

  • Cập nhật hệ điều hành và cài đặt các gói bổ trợ

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    
    3

  • Khai báo report cho MariaDB 10. x

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    
    4

  • Thực hiện cập nhật hệ điều hành

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    
    5

  • Thực hiện cài đặt MariaDB

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    
    6

  • Khởi động MariaDB

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    
    7

  • Kích hoạt MariaDB

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    
    8

  • Kiểm tra lại trạng thái hoạt động của MariaDB

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    
    9

  • Mở tường lửa để cho phép các máy ở xa kết nối với MySQL

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

  • Thực hiện thiết lập các cơ chế bảo đảm an toàn cho MariaDB

    sudo yum install -y mysql-server
    
    1

  • Ở bước hỏi đầu tiên này, ta nhấn

    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    4 bởi vì ở lần cài đặt MariaDB đầu tiên không có mật khẩu

    sudo yum install -y mysql-server
    
    2

  • Chọn

    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    6 khi được hỏi ở bước
    All done!  If you've completed all of the above steps, your MySQL
    installation should now be secure.
    
    Thanks for using MySQL!
    
    Cleaning up...
    
    5

    sudo yum install -y mysql-server
    
    3

  • In the next comment, select

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

    sudo yum install -y mysql-server
    
    4

  • Sau khi nhập mật khẩu cho tài khoản

    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    7 của MySQL. Ta sẽ có thông báo như bên dưới

    sudo yum install -y mysql-server
    
    5

  • Tiếp tục chọn

    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    6 ở màn hình tiếp theo, ở bước này sẽ thực hiện việc xóa tài khoản ẩn danh

    sudo yum install -y mysql-server
    
    6

  • Chọn

    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    6 tại màn hình
    [root@c7srv02 ~]# mysql -u root -p
    Enter password:
    
    0 để loại bỏ chế độ cho phép đăng nhập từ xa với tài khoản
    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    7 vào MariaDB

    sudo yum install -y mysql-server
    
    7

  • Chọn

    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    6 ở màn hình
    [root@c7srv02 ~]# mysql -u root -p
    Enter password:
    
    3 để xóa tên cơ sở dữ liệu là
    Password updated successfully!
    Reloading privilege tables..
    .. Success!
    
    7

    sudo yum install -y mysql-server
    
    8

  • Chọn

    firewall-cmd --add-service=mysql --permanent
    firewall-cmd --reload
    
    6 ở màn hình
    [root@c7srv02 ~]# mysql -u root -p
    Enter password:
    
    6 để thực hiện tải lại MariaDB

    sudo yum install -y mysql-server
    
    9

  • Ta sẽ nhận được thông báo cuối cùng như sau

    sudo systemctl start mysqld
    sudo systemctl enable mysqld
    
    0

Gostep this step ta đã thực hiện thiết lập ban đầu với MariaDB. Tuy nhiên, trong MariaDB 10. 3 trở về mặc định mặc dù đã thiết lập mật khẩu cho tài khoản

firewall-cmd --add-service=mysql --permanent
firewall-cmd --reload
7 nhưng ta vẫn có thể đăng nhập vào MariaDB mà không cần mật khẩu

  • Thực hiện đăng nhập

    sudo systemctl start mysqld
    sudo systemctl enable mysqld
    
    1

  • Tại dòng

    [root@c7srv02 ~]# mysql -u root -p
    Enter password:
    
    8 ấn Enter và không cần nhập gì cả, ta sẽ truy cập vào chế độ tương tác của MariaDB

    sudo systemctl start mysqld
    sudo systemctl enable mysqld
    
    2

  • Để xử lý công việc này, ta mở tệp

    [root@c7srv02 ~]# mysql -u root -p
    Enter password:
    
    9 và thêm dòng cấu hình
    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    
    00 tại thẻ
    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    
    01. Kết quả của tệp sửa đổi sẽ có dạng sau thẻ
    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    
    01

    sudo systemctl start mysqld
    sudo systemctl enable mysqld
    
    3

  • Khởi động lại MariaDB để áp dụng cấu hình vừa sửa ở trên

    sudo systemctl start mysqld
    sudo systemctl enable mysqld
    
    4

  • Thực hiện đăng nhập lại với lệnh

    All done!  If you've completed all of the above steps, your MySQL
    installation should now be secure.
    
    Thanks for using MySQL!
    
    Cleaning up...
    
    0, khi được hỏi nhập mật khẩu thiết lập ở bước trên là ok

    sudo systemctl start mysqld
    sudo systemctl enable mysqld
    
    5

Thực hiện các câu hỏi cơ bản

  • Kiểm tra các cơ sở dữ liệu có trong hệ thống

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    
    04. Kết quả

    sudo systemctl start mysqld
    sudo systemctl enable mysqld
    
    6

  • Kiểm tra danh sách những người dùng có trong bảng

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    
    05 của tên cơ sở dữ liệu là
    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum update -y
    
    06

    sudo systemctl start mysqld
    sudo systemctl enable mysqld
    
    7

Khi cần đứng từ máy khác kết nối với MySQL trên máy chủ, ta thực hiện thêm bước cấp quyền cho tài khoản gốc bằng lệnh sau