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 //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ẫnTại dòng
3 nhấnfirewall-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ậpfirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
Tại dòng
5 lựa chọnfirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
6 để bắt đầu nhập mật khẩu cho tài khoảnfirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
7 của MySQLfirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
Tài dòng
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ôngfirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
Password updated successfully! Reloading privilege tables.. .. Success!
Tại dòng
0 lựa chọn phímPassword updated successfully! Reloading privilege tables.. .. Success!
6 để xóa tài khoản vô danh được cung cấp mặc định ngay khi cài đặt MySQLfirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
Tại dòng
2 lựa chọn phímPassword updated successfully! Reloading privilege tables.. .. Success!
6 để vô hiệu hóa tính năng cho phép truy cập MySQL với tài khoảnfirewall-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]firewall-cmd --add-service=mysql --permanent firewall-cmd --reload
Tại dòng
5 lựa chọnPassword updated successfully! Reloading privilege tables.. .. Success!
6 để xóa cơ sở dữ liệu có tên làfirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
7 được sinh ra từ lệnh cấm đâuPassword updated successfully! Reloading privilege tables.. .. Success!
Tại dòng
8 lựa chọnPassword updated successfully! Reloading privilege tables.. .. Success!
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àfirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
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
0All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL! Cleaning up...
[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
0wget //repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update -y
- Thực hiện truy vấn sql cơ bản
1wget //repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update -y
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
7 của MySQL để có thể đăng nhập từ hệ thống khácfirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
2wget //repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update -y
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ợ
3wget //repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update -y
Khai báo report cho MariaDB 10. x
4wget //repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update -y
Thực hiện cập nhật hệ điều hành
5wget //repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update -y
Thực hiện cài đặt MariaDB
6wget //repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update -y
Khởi động MariaDB
7wget //repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update -y
Kích hoạt MariaDB
8wget //repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update -y
Kiểm tra lại trạng thái hoạt động của MariaDB
9wget //repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update -y
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
1sudo yum install -y mysql-server
Ở bước hỏi đầu tiên này, ta nhấn
4 bởi vì ở lần cài đặt MariaDB đầu tiên không có mật khẩufirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
2sudo yum install -y mysql-server
Chọn
6 khi được hỏi ở bướcfirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
5All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL! Cleaning up...
3sudo yum install -y mysql-server
In the next comment, select
6firewall-cmd --add-service=mysql --permanent firewall-cmd --reload
4sudo yum install -y mysql-server
Sau khi nhập mật khẩu cho tài khoản
7 của MySQL. Ta sẽ có thông báo như bên dướifirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
5sudo yum install -y mysql-server
Tiếp tục chọn
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 danhfirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
6sudo yum install -y mysql-server
Chọn
6 tại màn hìnhfirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
0 để loại bỏ chế độ cho phép đăng nhập từ xa với tài khoản[root@c7srv02 ~]# mysql -u root -p Enter password:
7 vào MariaDBfirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
7sudo yum install -y mysql-server
Chọn
6 ở màn hìnhfirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
3 để xóa tên cơ sở dữ liệu là[root@c7srv02 ~]# mysql -u root -p Enter password:
7Password updated successfully! Reloading privilege tables.. .. Success!
8sudo yum install -y mysql-server
Chọn
6 ở màn hìnhfirewall-cmd --add-service=mysql --permanent firewall-cmd --reload
6 để thực hiện tải lại MariaDB[root@c7srv02 ~]# mysql -u root -p Enter password:
9sudo yum install -y mysql-server
Ta sẽ nhận được thông báo cuối cùng như sau
0sudo systemctl start mysqld sudo systemctl enable mysqld
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ẩuThực hiện đăng nhập
1sudo systemctl start mysqld sudo systemctl enable mysqld
Tại dòng
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[root@c7srv02 ~]# mysql -u root -p Enter password:
2sudo systemctl start mysqld sudo systemctl enable mysqld
Để xử lý công việc này, ta mở tệp
9 và thêm dòng cấu hình[root@c7srv02 ~]# mysql -u root -p Enter password:
00 tại thẻwget //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 //repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update -y
01wget //repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update -y
3sudo systemctl start mysqld sudo systemctl enable mysqld
Khởi động lại MariaDB để áp dụng cấu hình vừa sửa ở trên
4sudo systemctl start mysqld sudo systemctl enable mysqld
Thực hiện đăng nhập lại với lệnh
0, khi được hỏi nhập mật khẩu thiết lập ở bước trên là okAll done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL! Cleaning up...
5sudo systemctl start mysqld sudo systemctl enable mysqld
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
04. Kết quảwget //repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update -y
6sudo systemctl start mysqld sudo systemctl enable mysqld
Kiểm tra danh sách những người dùng có trong bảng
05 của tên cơ sở dữ liệu làwget //repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update -y
06wget //repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update -y
7sudo systemctl start mysqld sudo systemctl enable mysqld
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