All Products
Search
Document Center

Elastic Compute Service:Instal MySQL pada instans Linux

Last Updated:Jun 21, 2026

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

  1. Hubungkan ke instans ECS. Untuk informasi lebih lanjut, lihat Masuk ke instans Linux menggunakan Workbench.

  2. 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
  3. Ambil password root sementara.

    echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD)
  4. Jalankan perintah berikut untuk memulai wizard instalasi aman MySQL.

    sudo mysql_secure_installation
    1. Masukkan password sementara untuk pengguna root.

      Catatan

      Password tidak ditampilkan saat Anda mengetik. Pastikan Anda memasukkannya dengan benar.

      Securing the MySQL server deployment.
      Enter password for user root:
    2. Saat diminta bahwa password root telah kedaluwarsa, tetapkan password baru untuk pengguna root. Anda harus memasukkan password baru tersebut dua kali.

      Penting

      Kebijakan 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:
    3. 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) :
    4. Pada prompt Remove anonymous users?, masukkan y.

      Catatan

      Menghapus 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) :
    5. Pada prompt Disallow root login remotely?, masukkan y untuk melarang login remote bagi pengguna root MySQL.

      Catatan

      Jika Anda perlu mengizinkan login remote root karena alasan tertentu, tekan tombol apa pun selain Y.

      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) :
    6. Pada prompt Remove test database and access to it?, masukkan y untuk menghapus database test bawaan.

      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) :
    7. 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

  1. Hubungkan ke instans ECS. Untuk informasi lebih lanjut, lihat Masuk ke instans Linux menggunakan Workbench.

  2. 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
  3. Ambil password root sementara.

    echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD)
  4. Jalankan perintah berikut untuk memulai wizard instalasi aman MySQL.

    sudo mysql_secure_installation
    1. Masukkan password sementara untuk pengguna root.

      Catatan

      Password tidak ditampilkan saat Anda mengetik. Pastikan Anda memasukkannya dengan benar.

      Securing the MySQL server deployment.
      Enter password for user root:
    2. Saat diminta bahwa password root telah kedaluwarsa, tetapkan password baru untuk pengguna root. Anda harus memasukkan password baru tersebut dua kali.

      Penting

      Kebijakan 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:
    3. 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) :
    4. Pada prompt Remove anonymous users?, masukkan y.

      Catatan

      Menghapus 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) :
    5. Pada prompt Disallow root login remotely?, masukkan y untuk melarang login remote bagi pengguna root MySQL.

      Catatan

      Jika Anda perlu mengizinkan login remote root karena alasan tertentu, tekan tombol apa pun selain Y.

      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) :
    6. Pada prompt Remove test database and access to it?, masukkan y untuk menghapus database test bawaan.

      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) :
    7. 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

  1. Hubungkan ke instans ECS. Untuk informasi lebih lanjut, lihat Masuk ke instans Linux menggunakan Workbench.

  2. 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
  3. Jalankan perintah berikut untuk memulai wizard instalasi aman MySQL.

    sudo mysql_secure_installation
    1. Pada prompt Would you like to setup VALIDATE PASSWORD component?, masukkan y untuk mengaktifkan komponen VALIDATE 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:
    2. 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:
    3. 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: 100
      Penting

      Kebijakan password mensyaratkan password minimal terdiri dari 8 karakter dan mengandung setidaknya satu huruf kapital, satu huruf kecil, satu angka, dan satu karakter khusus.

    4. 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) :
    5. Pada prompt Remove anonymous users?, masukkan y.

      Catatan

      Menghapus 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) :
    6. Pada prompt Disallow root login remotely?, masukkan y untuk melarang login remote bagi pengguna root MySQL.

      Catatan

      Jika Anda perlu mengizinkan login remote root karena alasan tertentu, tekan tombol apa pun selain Y.

      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) :
    7. Pada prompt Remove test database and access to it?, masukkan y untuk menghapus database test bawaan.

      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) :
    8. 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

  1. Hubungkan ke instans ECS. Untuk informasi lebih lanjut, lihat Masuk ke instans Linux menggunakan Workbench.

  2. 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
  3. Ambil password root sementara.

    echo $(PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log); PASSWORD=${PASSWORD##* }; echo $PASSWORD)
  4. Jalankan perintah berikut untuk memulai wizard instalasi aman MySQL.

    sudo mysql_secure_installation
    1. Masukkan password sementara untuk pengguna root.

      Catatan

      Password tidak ditampilkan saat Anda mengetik. Pastikan Anda memasukkannya dengan benar.

      Securing the MySQL server deployment.
      Enter password for user root:
    2. Saat diminta bahwa password root telah kedaluwarsa, tetapkan password baru untuk pengguna root. Anda harus memasukkan password baru tersebut dua kali.

      Penting

      Kebijakan 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:
    3. 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) :
    4. Pada prompt Remove anonymous users?, masukkan y.

      Catatan

      Menghapus 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) :
    5. Pada prompt Disallow root login remotely?, masukkan y untuk melarang login remote bagi pengguna root MySQL.

      Catatan

      Jika Anda perlu mengizinkan login remote root karena alasan tertentu, tekan tombol apa pun selain Y.

      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) :
    6. Pada prompt Remove test database and access to it?, masukkan y untuk menghapus database test bawaan.

      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) :
    7. 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

  1. Hubungkan ke instans ECS. Untuk informasi lebih lanjut, lihat Masuk ke instans Linux menggunakan Workbench.

  2. Jalankan perintah berikut untuk memperbarui daftar paket Anda.

    sudo apt-get update
  3. 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
    1. (Opsional) Jika skrip mysql-apt-config mendeteksi bahwa versi sistem operasi Anda tidak didukung secara resmi, antarmuka akan muncul. Pilih versi yang didukung paling kompatibel untuk melanjutkan.

      Catatan

      Untuk 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>
    2. 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>
  4. Instal server MySQL.

    Penting

    Selama instalasi, kotak dialog Configuring mysql-community-server akan meminta Anda menetapkan password untuk pengguna root MySQL. 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
  5. Jalankan perintah berikut untuk memulai wizard instalasi aman MySQL.

    sudo mysql_secure_installation
    1. Masukkan password untuk pengguna root.

    2. Pada prompt Would you like to setup VALIDATE PASSWORD component?, masukkan y untuk mengaktifkan komponen VALIDATE 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:
    3. 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:
    4. Karena Anda telah menetapkan password root pada langkah instalasi apt, Anda dapat melewati pengubahan password sekarang. Masukkan n untuk melanjutkan.

      Catatan

      Jika Anda perlu mengubah password pengguna root, masukkan y.

    5. Pada prompt Remove anonymous users?, masukkan y.

      Catatan

      Menghapus 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) :
    6. Pada prompt Disallow root login remotely?, masukkan y untuk melarang login remote bagi pengguna root MySQL.

      Catatan

      Jika Anda perlu mengizinkan login remote root karena alasan tertentu, tekan tombol apa pun selain Y.

      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) :
    7. Pada prompt Remove test database and access to it?, masukkan y untuk menghapus database test bawaan.

      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) :
    8. 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

  1. Hubungkan ke instans ECS. Untuk informasi lebih lanjut, lihat Masuk ke instans Linux menggunakan Workbench.

  2. 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.

  3. 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;"
  4. 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

Referensi

FAQ