Yêu cầu:
Bạn nên sử dụng tài khoản người dùng không phải root như được giải thích trong Khởi tạo máy chủ Ubuntu 20.04.
Cài đặt MySQL Server
Hãy bắt đầu bằng cách cập nhật kho lưu trữ và cài đặt gói MySQL cho Ubuntu 20.04 bằng apt
.
sudo apt update && sudo apt install mysql-server
Nhấn y
và ENTER
khi được nhắc cài đặt gói MySQL.
Sau khi trình cài đặt gói hoàn tất, chúng ta có thể kiểm tra xem dịch vụ MySQL có đang chạy hay không.
sudo service mysql status
Bạn sẽ thấy trạng thái Active màu xanh như bên dưới.
Nhấn q
để thoát khỏi trạng thái dịch vụ.
Cấu hình Security cho MySQL
Bây giờ bạn nên chạy mysql_secure_installation
để định cấu hình bảo mật cho máy chủ MySQL của mình.
sudo mysql_secure_installation
Xác thực mật khẩu (Tùy chọn)
Bạn sẽ được hỏi xem liệu bạn có muốn thiết lập Validate Password Plugin hay không. Nó không thực sự cần thiết trừ khi bạn muốn thực thi các chính sách mật khẩu nghiêm ngặt vì một số lý do.
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
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?
Press y|Y for Yes, any other key for No:
Nhấn ENTER
nếu bạn không muốn thiết lập Validate Password Plugin.
Tạo root password
Nếu bạn chưa tạo mật khẩu cho root, thì bây giờ bạn phải tạo mật khẩu gốc tại đây.
Please set the password for root here.
New password:
Re-enter new password:
Hãy tạo một mật khẩu đủ mạnh. Lưu ý rằng khi bạn nhập mật khẩu trong Linux, sẽ không có gì hiển thị khi bạn đang nhập (không có dấu sao hoặc dấu chấm).
Xóa người dùng ẩn danh
Tiếp theo bạn sẽ được yêu cầu xóa người dùng ẩn danh.
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) :
Press y
and ENTER
to remove anonymous users.
Vô hiệu hóa đăng nhập root từ xa
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) :
Nhấn y
và ENTER
để không cho phép đăng nhập root từ xa. Điều này sẽ ngăn chặn bot và tin tặc cố gắng đoán mật khẩu gốc.
Xóa cơ sở dữ liệu “test”
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) :
Nhấn y
và ENTER
để xóa cơ sở dữ liệu tên “test”
Tải lại các bảng dữ liệu
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) :
Test MySQL Service
sudo mysql
Để thoát MySQL, gõ exit
và nhấn ENTER
.
exit