Cài đặt MySQL, MariaDB trên Ubuntu

Giới thiệu
Cài đặt MySQL và MariaDB trên Ubuntu là một bước quan trọng để thiết lập một cơ sở dữ liệu mạnh mẽ và hiệu quả cho các ứng dụng và dịch vụ của bạn. Trong bài viết này, chúng tôi sẽ hướng dẫn bạn từng bước để cài đặt cả MySQL và MariaDB trên hệ điều hành Ubuntu. Bạn sẽ tìm hiểu cách thực hiện cài đặt từ các kho lưu trữ chính thức, cấu hình cơ bản và các bước kiểm tra để đảm bảo rằng cơ sở dữ liệu của bạn hoạt động đúng cách. Dù bạn đang sử dụng MySQL hay MariaDB, hướng dẫn này sẽ giúp bạn thiết lập môi trường cơ sở dữ liệu ổn định và sẵn sàng cho các nhiệm vụ phát triển và quản lý.
Install MySQL 5.7
Add MySQL 5.7 APT Repository :
wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
Install the repository :
sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb
Update the APT repository :
sudo apt update
Nếu bạn gặp lỗi ” signature couldn’t be verified ” hãy import lại GPG key :
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
Chạy lại apt update
Kiểm tra lại MySQL repository :
sudo apt-cache policy mysql-server
Install MySQL 5.7 :
sudo apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7* -y
INSTALL MySQL 8.0
Install MySQL 8.0:
apt -y install mysql-server-8.0
Verify :
sudo mysql_secure_installation
[sudo] password for toor:
Securing the MySQL server deployment.
Enter password for user root:
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: Y
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Using existing password for root.
Estimated strength of the password: 0
Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y
New password:
Re-enter new password:
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
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!
MariaDB 11.4.x
sudo apt-get install apt-transport-https curl
sudo mkdir -p /etc/apt/keyrings
sudo curl -o /etc/apt/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp'
Sau khi đã Import Key, copy và paste dòng dưới vào /etc/apt/sources.list.d
(for instance /etc/apt/sources.list.d/mariadb.sources
):
# MariaDB 11.4 repository list - created 2024-09-02 14:54 UTC
# https://mariadb.org/download/
X-Repolib-Name: MariaDB
Types: deb
# deb.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
# URIs: https://deb.mariadb.org/11.4/ubuntu
URIs: https://vn-mirrors.vhost.vn/mariadb/repo/11.4/ubuntu
Suites: focal
Components: main main/debug
Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp
Install MariaDB :
sudo apt-get update
sudo apt-get install mariadb-server
Việc cài đặt MySQL và MariaDB trên Ubuntu không chỉ cung cấp cho bạn một nền tảng cơ sở dữ liệu mạnh mẽ mà còn giúp bạn bắt đầu nhanh chóng với các dự án phát triển và quản lý dữ liệu. Đừng quên kiểm tra và cập nhật hệ thống thường xuyên để duy trì sự ổn định và bảo mật !
Post Comment