Topik ini menjelaskan cara melakukan deploy versi tertentu dari database MySQL secara manual pada instans Linux ECS.
Prasyarat
-
Alamat IP publik secara otomatis ditetapkan ke instans ECS atau alamat IP elastis (EIP) dikaitkan dengan instans tersebut. Untuk petunjuk cara mengaktifkan bandwidth publik, lihat Aktifkan bandwidth publik.
-
ECS harus memiliki aturan inbound pada security group yang mengizinkan traffic pada port 22. Untuk petunjuknya, lihat Tambahkan aturan security group.
Deploy MySQL
Alibaba Cloud Linux 3
-
Hubungkan ke instans ECS. Untuk informasi lebih lanjut, lihat Masuk ke instans Linux menggunakan Workbench.
-
Instal database MySQL.
# Instal compat-openssl10 untuk kompatibilitas dengan library OpenSSL lama. sudo yum install -y compat-openssl10 # Tambahkan repositori resmi MySQL. sudo rpm -Uvh https://repo.mysql.com/mysql84-community-release-el8-1.noarch.rpm # Instal layanan MySQL. sudo dnf install -y mysql-server # Mulai layanan MySQL dan aktifkan agar berjalan saat boot. sudo systemctl start mysqld sudo systemctl enable mysqld -
Ambil password root sementara.
echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD) -
Jalankan perintah berikut untuk memulai wizard instalasi aman MySQL.
sudo mysql_secure_installation-
Masukkan password sementara untuk pengguna
root.CatatanPassword tidak ditampilkan saat Anda mengetik. Pastikan Anda memasukkannya dengan benar.
Securing the MySQL server deployment. Enter password for user root: -
Saat diminta bahwa password root telah kedaluwarsa, tetapkan password baru untuk pengguna
root. Anda harus memasukkan password baru tersebut dua kali.PentingKebijakan password mensyaratkan password minimal terdiri dari 8 karakter dan mengandung setidaknya satu huruf kapital, satu huruf kecil, satu angka, dan satu karakter khusus.
The existing password for the user account root has expired. Please set a new password. New password: Re-enter new password: -
Setelah Anda mengubah password
root, masukkan n untuk melewati pengubahan password lagi.Change the password for root ? (Press y|Y for Yes, any other key for No) : -
Pada prompt
Remove anonymous users?, masukkan y.CatatanMenghapus pengguna anonim membantu mencegah akses ke server MySQL tanpa akun pengguna.
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) : -
Pada prompt
Disallow root login remotely?, masukkan y untuk melarang login remote bagi penggunarootMySQL.CatatanJika Anda perlu mengizinkan login remote
rootkarena alasan tertentu, tekan tombol apa pun selainY.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) : -
Pada prompt
Remove test database and access to it?, masukkan y untuk menghapus databasetestbawaan.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) : -
Pada prompt
Reload privilege tables now?, masukkan y untuk menerapkan perubahan Anda.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) :
-
Alibaba Cloud Linux 2
-
Hubungkan ke instans ECS. Untuk informasi lebih lanjut, lihat Masuk ke instans Linux menggunakan Workbench.
-
Instal database MySQL.
# Tambahkan repositori resmi MySQL. sudo rpm -Uvh https://repo.mysql.com/mysql84-community-release-el7-1.noarch.rpm # Instal layanan MySQL. sudo yum install -y mysql-server # Mulai layanan MySQL dan aktifkan agar berjalan saat boot. sudo systemctl start mysqld sudo systemctl enable mysqld -
Ambil password root sementara.
echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD) -
Jalankan perintah berikut untuk memulai wizard instalasi aman MySQL.
sudo mysql_secure_installation-
Masukkan password sementara untuk pengguna
root.CatatanPassword tidak ditampilkan saat Anda mengetik. Pastikan Anda memasukkannya dengan benar.
Securing the MySQL server deployment. Enter password for user root: -
Saat diminta bahwa password root telah kedaluwarsa, tetapkan password baru untuk pengguna
root. Anda harus memasukkan password baru tersebut dua kali.PentingKebijakan password mensyaratkan password minimal terdiri dari 8 karakter dan mengandung setidaknya satu huruf kapital, satu huruf kecil, satu angka, dan satu karakter khusus.
The existing password for the user account root has expired. Please set a new password. New password: Re-enter new password: -
Setelah Anda mengubah password
root, masukkan n untuk melewati pengubahan password lagi.Change the password for root ? (Press y|Y for Yes, any other key for No) : -
Pada prompt
Remove anonymous users?, masukkan y.CatatanMenghapus pengguna anonim membantu mencegah akses ke server MySQL tanpa akun pengguna.
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) : -
Pada prompt
Disallow root login remotely?, masukkan y untuk melarang login remote bagi penggunarootMySQL.CatatanJika Anda perlu mengizinkan login remote
rootkarena alasan tertentu, tekan tombol apa pun selainY.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) : -
Pada prompt
Remove test database and access to it?, masukkan y untuk menghapus databasetestbawaan.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) : -
Pada prompt
Reload privilege tables now?, masukkan y untuk menerapkan perubahan Anda.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) :
-
CentOS 8
-
Hubungkan ke instans ECS. Untuk informasi lebih lanjut, lihat Masuk ke instans Linux menggunakan Workbench.
-
Instal database MySQL.
# Tambahkan repositori resmi MySQL. sudo rpm -Uvh https://repo.mysql.com/mysql84-community-release-el8-1.noarch.rpm # Instal layanan MySQL. sudo dnf install -y mysql-server # Mulai layanan MySQL dan aktifkan agar berjalan saat boot. sudo systemctl start mysqld sudo systemctl enable mysqld -
Jalankan perintah berikut untuk memulai wizard instalasi aman MySQL.
sudo mysql_secure_installation-
Pada prompt
Would you like to setup VALIDATE PASSWORD component?, masukkan y untuk mengaktifkan komponenVALIDATE PASSWORD.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: -
Masukkan 2 untuk mengatur tingkat kebijakan password ke
STRONG. Kebijakan ini mensyaratkan password minimal terdiri dari 8 karakter, mengandung angka, huruf campuran (kapital dan kecil), karakter khusus, serta tidak berdasarkan file kamus.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: -
Tetapkan password baru untuk pengguna
root. Anda harus memasukkan password baru tersebut dua kali.New password: Re-enter new password: Estimated strength of the password: 100PentingKebijakan password mensyaratkan password minimal terdiri dari 8 karakter dan mengandung setidaknya satu huruf kapital, satu huruf kecil, satu angka, dan satu karakter khusus.
-
Pada prompt
Do you wish to continue with the password provided?, masukkan y.Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : -
Pada prompt
Remove anonymous users?, masukkan y.CatatanMenghapus pengguna anonim membantu mencegah akses ke server MySQL tanpa akun pengguna.
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) : -
Pada prompt
Disallow root login remotely?, masukkan y untuk melarang login remote bagi penggunarootMySQL.CatatanJika Anda perlu mengizinkan login remote
rootkarena alasan tertentu, tekan tombol apa pun selainY.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) : -
Pada prompt
Remove test database and access to it?, masukkan y untuk menghapus databasetestbawaan.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) : -
Pada prompt
Reload privilege tables now?, masukkan y untuk menerapkan perubahan Anda.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) :
-
CentOS 7
-
Hubungkan ke instans ECS. Untuk informasi lebih lanjut, lihat Masuk ke instans Linux menggunakan Workbench.
-
Instal database MySQL.
# Tambahkan repositori resmi MySQL. sudo rpm -Uvh https://repo.mysql.com/mysql84-community-release-el7-1.noarch.rpm # Instal layanan MySQL. sudo yum install -y mysql-server # Mulai layanan MySQL dan aktifkan agar berjalan saat boot. sudo systemctl start mysqld sudo systemctl enable mysqld -
Ambil password root sementara.
echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD) -
Jalankan perintah berikut untuk memulai wizard instalasi aman MySQL.
sudo mysql_secure_installation-
Masukkan password sementara untuk pengguna
root.CatatanPassword tidak ditampilkan saat Anda mengetik. Pastikan Anda memasukkannya dengan benar.
Securing the MySQL server deployment. Enter password for user root: -
Saat diminta bahwa password root telah kedaluwarsa, tetapkan password baru untuk pengguna
root. Anda harus memasukkan password baru tersebut dua kali.PentingKebijakan password mensyaratkan password minimal terdiri dari 8 karakter dan mengandung setidaknya satu huruf kapital, satu huruf kecil, satu angka, dan satu karakter khusus.
The existing password for the user account root has expired. Please set a new password. New password: Re-enter new password: -
Setelah Anda mengubah password
root, masukkan n untuk melewati pengubahan password lagi.Change the password for root ? (Press y|Y for Yes, any other key for No) : -
Pada prompt
Remove anonymous users?, masukkan y.CatatanMenghapus pengguna anonim membantu mencegah akses ke server MySQL tanpa akun pengguna.
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) : -
Pada prompt
Disallow root login remotely?, masukkan y untuk melarang login remote bagi penggunarootMySQL.CatatanJika Anda perlu mengizinkan login remote
rootkarena alasan tertentu, tekan tombol apa pun selainY.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) : -
Pada prompt
Remove test database and access to it?, masukkan y untuk menghapus databasetestbawaan.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) : -
Pada prompt
Reload privilege tables now?, masukkan y untuk menerapkan perubahan Anda.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) :
-
Ubuntu/Debian
-
Hubungkan ke instans ECS. Untuk informasi lebih lanjut, lihat Masuk ke instans Linux menggunakan Workbench.
-
Jalankan perintah berikut untuk memperbarui daftar paket Anda.
sudo apt-get update -
Instal repositori APT MySQL.
# Unduh paket konfigurasi APT. sudo wget https://dev.mysql.com/get/mysql-apt-config_0.8.33-1_all.deb # Gunakan perintah dpkg untuk menginstal paket konfigurasi APT MySQL yang telah diunduh. sudo dpkg -i mysql-apt-config_0.8.33-1_all.deb-
(Opsional) Jika skrip
mysql-apt-configmendeteksi bahwa versi sistem operasi Anda tidak didukung secara resmi, antarmuka akan muncul. Pilih versi yang didukung paling kompatibel untuk melanjutkan.CatatanUntuk mengetahui codename sistem Anda, lihat FAQ.
Configuring mysql-apt-config The detected system (ubuntu bionic) is not supported by MySQL. If you believe the platform is compatible with one of the supported systems, one of the corresponding repositories may be selected. Add repository to unsupported system? ubuntu lunar ubuntu focal ubuntu jammy ubuntu noble ubuntu oracular debian bookworm abort <Ok> -
Laman konfigurasi mencantumkan semua komponen yang akan diinstal, termasuk MySQL Server, Client, dan Tools. Verifikasi versi dan komponennya, gunakan tombol panah untuk menavigasi ke
Ok, lalu tekan Enter.Configuring mysql-apt-config The MySQL APT Repository features MySQL Server along with a variety of components. You may select the desired products to install and update from the official MySQL Repository, and also select the associated version series. Select "Ok" to save the configuration, and then execute "apt update" to load the selected package list. This configuration can be updated later, depending on your needs. Which MySQL product do you wish to configure? MySQL Server & Cluster (Currently selected: mysql-8.4-lts) MySQL Connectors (Currently selected: Enabled) Ok <Ok>
-
-
Instal server MySQL.
PentingSelama instalasi, kotak dialog Configuring mysql-community-server akan meminta Anda menetapkan password untuk pengguna
rootMySQL. Kebijakan password mensyaratkan password minimal terdiri dari 8 karakter dan mencakup satu huruf kapital, satu huruf kecil, satu angka, dan satu karakter khusus. Pada bidang Enter root password, masukkan password Anda dan pilih Ok. Pada kotak dialog Configuring mysql-community-server berikutnya, masukkan ulang password pada bidang Re-enter root password dan pilih Ok untuk mengonfirmasi. Jika Anda membiarkan bidang password kosong, otentikasi UNIX socket akan diaktifkan. Simpan password ini dengan aman.# Perbarui daftar paket. sudo apt update # Instal server MySQL. sudo apt install -y mysql-server # Mulai layanan MySQL. sudo systemctl start mysql # Periksa status layanan. sudo systemctl status mysql # Aktifkan layanan agar berjalan saat boot. sudo systemctl enable mysql -
Jalankan perintah berikut untuk memulai wizard instalasi aman MySQL.
sudo mysql_secure_installation-
Masukkan password untuk pengguna
root. -
Pada prompt
Would you like to setup VALIDATE PASSWORD component?, masukkan y untuk mengaktifkan komponenVALIDATE PASSWORD.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: -
Masukkan 2 untuk mengatur tingkat kebijakan password ke
STRONG. Kebijakan ini mensyaratkan password minimal terdiri dari 8 karakter, mengandung angka, huruf campuran (kapital dan kecil), karakter khusus, serta tidak berdasarkan file kamus.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: -
Karena Anda telah menetapkan password root pada langkah instalasi apt, Anda dapat melewati pengubahan password sekarang. Masukkan n untuk melanjutkan.
CatatanJika Anda perlu mengubah password pengguna
root, masukkany. -
Pada prompt
Remove anonymous users?, masukkan y.CatatanMenghapus pengguna anonim membantu mencegah akses ke server MySQL tanpa akun pengguna.
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) : -
Pada prompt
Disallow root login remotely?, masukkan y untuk melarang login remote bagi penggunarootMySQL.CatatanJika Anda perlu mengizinkan login remote
rootkarena alasan tertentu, tekan tombol apa pun selainY.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) : -
Pada prompt
Remove test database and access to it?, masukkan y untuk menghapus databasetestbawaan.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) : -
Pada prompt
Reload privilege tables now?, masukkan y untuk menerapkan perubahan Anda.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) :
-
Tambahkan pengguna MySQL remote
-
Hubungkan ke instans ECS. Untuk informasi lebih lanjut, lihat Masuk ke instans Linux menggunakan Workbench.
-
Pastikan security group instans memiliki aturan inbound yang mengizinkan traffic pada port 3306. Jika Anda menggunakan port berbeda, sesuaikan pengaturan security group tersebut. Untuk informasi lebih lanjut, lihat Tambahkan aturan security group.
-
Jalankan perintah berikut untuk membuat pengguna dan memberikan izin akses remote ke semua database MySQL.
Penting-
Ganti
<username>dengan username yang ingin Anda buat. -
Ganti
<password>dengan password untuk pengguna MySQL. Password harus minimal terdiri dari 8 karakter dan mencakup satu huruf kapital, satu huruf kecil, satu angka, dan satu karakter khusus.
# Setelah menjalankan perintah, masukkan password untuk pengguna root. sudo mysql -uroot -p \ -e "CREATE USER '<username>'@'%' IDENTIFIED BY '<password>';" \ -e "GRANT ALL PRIVILEGES ON *.* TO '<username>'@'%' WITH GRANT OPTION;" \ -e "FLUSH PRIVILEGES;" -
-
Verifikasi koneksi dengan menggunakan kredensial pengguna baru.
# Ganti <username> dengan nama pengguna dari pengguna yang Anda buat. Setelah Anda menjalankan perintah, masukkan kata sandi untuk pengguna baru. sudo mysql -u<username> -p