GNU/Linux >> Belajar Linux >  >> Cent OS

Cara Instal MySQL 8.0 di CentOS 8 / RHEL 8

MySQL adalah perangkat lunak Sistem manajemen basis data gratis yang paling umum digunakan dalam aplikasi tiga tingkat untuk menyimpan dan mengambil catatan dan informasi.

MySQL awalnya dikembangkan oleh MYSQL AB, sekarang dimiliki oleh Oracle Corporation. Itu adalah aplikasi database utama di Linux sampai MariaDB, sebuah fork dari MySQL, muncul.

Pada artikel ini, kita akan melihat langkah-langkah tentang cara menginstal MySQL 8.0 di CentOS 8 / RHEL 8.

Langkah-langkah yang disebutkan dalam artikel ini hanya akan berfungsi jika Anda telah mengaktifkan langganan di RHEL 8 atau mengonfigurasi repositori yum lokal di sistem Anda.

Instal MySQL 8.0 Pada CentOS 8 / RHEL 8

MySQL 8.0 tersedia untuk CentOS 8 / RHEL 8 dari repositori OS AppStream dan repositori MySQL Dev Community. 1. Instal MySQL 8.0 dari MySQL Dev Community 2. Instal MySQL 8.0 dari AppStream

1. Instal MySQL 8.0 dari Komunitas Dev MySQL

Tambahkan repositori resmi MySQL untuk menginstal server komunitas MySQL.

rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm

Pastikan repositori MySQL telah ditambahkan dan diaktifkan dengan menggunakan perintah berikut.

dnf repolist all | grep mysql | grep enabled

Keluaran:

mysql-connectors-community         MySQL Connectors Community           enabled
mysql-tools-community              MySQL Tools Community                enabled
mysql80-community                  MySQL 8.0 Community Server           enabled

Gunakan perintah dnf di CentOS/RHEL untuk menginstal MySQL versi stabil terbaru. Nonaktifkan repositori AppStream sementara untuk menginstal MySQL dari Komunitas Dev MySQL.

### CentOS 8 ###

dnf install -y --disablerepo=appstream mysql-community-server

### RHEL 8 ###

dnf install -y --disablerepo=rhel-8-for-x86_64-appstream-rpms mysql-community-server

Keluaran:

Dependencies resolved.
========================================================================================================================================================================
 Package                                             Architecture                Version                                   Repository                              Size
========================================================================================================================================================================
Installing:
 mysql-community-server                              x86_64                      8.0.25-1.el8                              mysql80-community                       53 M
Installing dependencies:
 mysql-community-client                              x86_64                      8.0.25-1.el8                              mysql80-community                       13 M
 mysql-community-client-plugins                      x86_64                      8.0.25-1.el8                              mysql80-community                       98 k
 mysql-community-common                              x86_64                      8.0.25-1.el8                              mysql80-community                      618 k
 mysql-community-libs                                x86_64                      8.0.25-1.el8                              mysql80-community                      1.4 M
 perl-Carp                                           noarch                      1.42-396.el8                              baseos                                  29 k
.     .     .
.     .     .
(36/37): mysql-community-client-8.0.25-1.el8.x86_64.rpm                                                                                 2.3 MB/s |  13 MB     00:05
(37/37): mysql-community-server-8.0.25-1.el8.x86_64.rpm                                                                                 5.0 MB/s |  53 MB     00:10
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                   4.4 MB/s |  79 MB     00:17
warning: /var/cache/dnf/mysql80-community-b1f1ed5ba88ce0f8/packages/mysql-community-client-8.0.25-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
MySQL 8.0 Community Server                                                                                                               27 MB/s |  27 kB     00:00
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <[email protected]>"
 Fingerprint: A4A9 4068 76FC BD3C 4567 70C8 8C71 8D3B 5072 E1F5
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                1/1
  Installing       : perl-Pod-Escapes-1:1.07-395.el8.noarch                                                                                                        1/37
.     .     .
.     .     .
  perl-Term-Cap-1.17-395.el8.noarch                   perl-Text-ParseWords-3.30-395.el8.noarch                    perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch
  perl-Time-Local-1:1.280-1.el8.noarch                perl-Unicode-Normalize-1.25-396.el8.x86_64                  perl-constant-1.33-396.el8.noarch
  perl-interpreter-4:5.26.3-419.el8.x86_64            perl-libs-4:5.26.3-419.el8.x86_64                           perl-macros-4:5.26.3-419.el8.x86_64
  perl-parent-1:0.237-1.el8.noarch                    perl-podlators-4.11-1.el8.noarch                            perl-threads-1:2.21-2.el8.x86_64
  perl-threads-shared-1.58-2.el8.x86_64

Complete!

2. Instal MySQL 8.0 dari AppStream

MySQL sekarang tersedia melalui Application Stream (Red Hat Enterprise Linux 8 untuk x86_64 – AppStream (RPM)) untuk RHEL 8 dan CentOS 8. Jadi, Anda tidak perlu menambahkan repositori resmi MySQL untuk menginstal server MySQL di RHEL 8.

Periksa apakah repositori AppStream diaktifkan di RHEL 8 menggunakan perintah berikut.

subscription-manager repos --list-enabled

Keluaran:

+----------------------------------------------------------+
    Available Repositories in /etc/yum.repos.d/redhat.repo
+----------------------------------------------------------+
Repo ID:   rhel-8-for-x86_64-baseos-rpms
Repo Name: Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)
Repo URL:  https://cdn.redhat.com/content/dist/rhel8/$releasever/x86_64/baseos/os
Enabled:   1

Repo ID:   rhel-8-for-x86_64-appstream-rpms
Repo Name: Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)
Repo URL:  https://cdn.redhat.com/content/dist/rhel8/$releasever/x86_64/appstream/os
Enabled:   1

Gunakan perintah dnf untuk menginstal MySQL versi terbaru.

dnf install -y @mysql

Keluaran:

Last metadata expiration check: 0:01:25 ago on Fri 11 Oct 2019 03:35:47 PM UTC.
Dependencies resolved.
===================================================================================================================
 Package                            Arch         Version                                     Repository       Size
===================================================================================================================
Installing group/module packages:
 mysql-server                       x86_64       8.0.13-1.module_el8.0.0+41+ca30bab6         AppStream        25 M
Installing dependencies:
 mariadb-connector-c-config         noarch       3.0.7-1.el8                                 AppStream        13 k
 mecab                              x86_64       0.996-1.module_el8.0.0+41+ca30bab6.9        AppStream       397 k
 mysql                              x86_64       8.0.13-1.module_el8.0.0+41+ca30bab6         AppStream       9.2 M
 mysql-common                       x86_64       8.0.13-1.module_el8.0.0+41+ca30bab6         AppStream       142 k
 mysql-errmsg                       x86_64       8.0.13-1.module_el8.0.0+41+ca30bab6         AppStream       523 k
 perl-Digest                        noarch       1.17-395.el8                                AppStream        27 k
 perl-Digest-MD5                    x86_64       2.55-396.el8                                AppStream        37 k
 perl-Net-SSLeay                    x86_64       1.85-6.el8                                  AppStream       358 k
 perl-URI                           noarch       1.73-3.el8                                  AppStream       116 k
.      .      .
.      .      .
Enabling module streams:
 mysql                                           8.0                                                              

Transaction Summary
===================================================================================================================
Install  51 Packages

Total download size: 48 M
Installed size: 278 M
Downloading Packages:
(1/51): mariadb-connector-c-config-3.0.7-1.el8.noarch.rpm                           12 kB/s |  13 kB     00:01    
(2/51): mysql-common-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64.rpm                1.3 MB/s | 142 kB     00:00    
(3/51): mecab-0.996-1.module_el8.0.0+41+ca30bab6.9.x86_64.rpm                      328 kB/s | 397 kB     00:01    
(4/51): mysql-errmsg-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64.rpm                5.7 MB/s | 523 kB     00:00    
(5/51): perl-Digest-1.17-395.el8.noarch.rpm                                        530 kB/s |  27 kB     00:00    
(6/51): perl-Digest-MD5-2.55-396.el8.x86_64.rpm                                    959 kB/s |  37 kB     00:00    
(7/51): mysql-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64.rpm                       6.3 MB/s | 9.2 MB     00:01    
.      .      .
.      .      .
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                           1/1 
  Installing       : perl-Exporter-5.72-396.el8.noarch                                                        1/51 
  Installing       : perl-libs-4:5.26.3-416.el8.x86_64                                                        2/51 
  Installing       : perl-Carp-1.42-396.el8.noarch                                                            3/51 
  Installing       : perl-Scalar-List-Utils-3:1.49-2.el8.x86_64                                               4/51 
  Installing       : perl-parent-1:0.237-1.el8.noarch                                                         5/51 
.      .      .
.      .      .
Installed:
  mysql-server-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64  perl-IO-Socket-IP-0.39-5.el8.noarch                     
  perl-IO-Socket-SSL-2.060-2.el8.noarch                    perl-Mozilla-CA-20160104-7.el8.noarch                   
  mariadb-connector-c-config-3.0.7-1.el8.noarch            mecab-0.996-1.module_el8.0.0+41+ca30bab6.9.x86_64       
  mysql-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64         mysql-common-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64 
  mysql-errmsg-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64  perl-Digest-1.17-395.el8.noarch                         
  perl-Digest-MD5-2.55-396.el8.x86_64                      perl-Net-SSLeay-1.85-6.el8.x86_64                       
  perl-URI-1.73-3.el8.noarch                               perl-libnet-3.11-3.el8.noarch                           
  protobuf-lite-3.5.0-7.el8.x86_64                         libaio-0.3.110-12.el8.x86_64                            
  numactl-libs-2.0.12-2.el8.x86_64                         perl-Carp-1.42-396.el8.noarch                           
  perl-Data-Dumper-2.167-399.el8.x86_64                    perl-Encode-4:2.97-3.el8.x86_64                         
  perl-Errno-1.28-416.el8.x86_64                           perl-Exporter-5.72-396.el8.noarch                       
  perl-File-Path-2.15-2.el8.noarch                         perl-File-Temp-0.230.600-1.el8.noarch                   
  perl-Getopt-Long-1:2.50-4.el8.noarch                     perl-HTTP-Tiny-0.074-1.el8.noarch                       
  perl-IO-1.38-416.el8.x86_64                              perl-MIME-Base64-3.15-396.el8.x86_64                    
  perl-PathTools-3.74-1.el8.x86_64                         perl-Pod-Escapes-1:1.07-395.el8.noarch                  
  perl-Pod-Perldoc-3.28-396.el8.noarch                     perl-Pod-Simple-1:3.35-395.el8.noarch                   
  perl-Pod-Usage-4:1.69-395.el8.noarch                     perl-Scalar-List-Utils-3:1.49-2.el8.x86_64              
  perl-Socket-4:2.027-2.el8.x86_64                         perl-Storable-1:3.11-3.el8.x86_64                       
  perl-Term-ANSIColor-4.06-396.el8.noarch                  perl-Term-Cap-1.17-395.el8.noarch                       
  perl-Text-ParseWords-3.30-395.el8.noarch                 perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch            
  perl-Time-Local-1:1.280-1.el8.noarch                     perl-Unicode-Normalize-1.25-396.el8.x86_64              
  perl-constant-1.33-396.el8.noarch                        perl-interpreter-4:5.26.3-416.el8.x86_64                
  perl-libs-4:5.26.3-416.el8.x86_64                        perl-macros-4:5.26.3-416.el8.x86_64                     
  perl-parent-1:0.237-1.el8.noarch                         perl-podlators-4.11-1.el8.noarch                        
  perl-threads-1:2.21-2.el8.x86_64                         perl-threads-shared-1.58-2.el8.x86_64                   
  policycoreutils-python-utils-2.8-16.1.el8.noarch        

Complete!

Mengelola Layanan server MySQL

Setelah instalasi MySQL, mulai layanan server MySQL menggunakan perintah berikut.

systemctl start mysqld

Aktifkan server MySQL saat startup sistem.

systemctl enable mysqld

Verifikasi bahwa server MySQL dimulai menggunakan perintah berikut.

systemctl status mysqld

Keluaran:

 mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2021-07-02 00:08:12 EDT; 11s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 3794 (mysqld)
   Status: "Server is operational"
    Tasks: 38 (limit: 23664)
   Memory: 442.0M
   CGroup: /system.slice/mysqld.service
           └─3794 /usr/sbin/mysqld

Jul 02 00:08:01 rocky8.itzgeek.local systemd[1]: Starting MySQL Server...
Jul 02 00:08:12 rocky8.itzgeek.local systemd[1]: Started MySQL Server.

Server MySQL aman

Menginstal MySQL dari Komunitas Dev MySQL

Di CentOS 8 / RHEL 8, kata sandi root MySQL awal dapat ditemukan di /var/log/mysqld.log. Anda dapat menggunakan perintah di bawah ini untuk mengambil kata sandi dari file log.

cat /var/log/mysqld.log | grep -i 'temporary password'

Keluaran:

2021-07-02T04:08:05.488758Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: PlrS,Tw&d9q2

Sekarang, Anda perlu menjalankan mysql_secure_installation untuk mengamankan instalasi MySQL Anda. Perintah ini menangani pengaturan kata sandi root, menghapus pengguna anonim, melarang login root dari jarak jauh, dll.

mysql_secure_installation

Keluaran:

Securing the MySQL server deployment.

Enter password for user root:   << Enter the temporary password you got from the previous step

The existing password for the user account root has expired. Please set a new password.

New password:   << Enter new root password

Re-enter new password:   << Re-enter new root password
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N  << Type N and Enter as we have already set root password

 ... skipping.
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  << Remove anonymous user
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  << Disallow root login remotely
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  << Remove test database
 - 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  << Reload privilege tables
Success.

All done!

Menginstal MySQL dari AppStream

Di CentOS 8 / RHEL 8, tidak ada kata sandi yang disetel untuk pengguna root MySQL . Jadi, kami akan menjalankan mysql_secure_installation untuk mengamankan instalasi MySQL Anda dengan mengatur kata sandi root, menghapus pengguna anonim, melarang login root dari jarak jauh, dll.

mysql_secure_installation

Keluaran:

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: Y    << Type Y to use VALIDATE PASSWORD COMPONENT to check strength of passwords

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: 1    << Choose the Level of Strongness
Please set the password for root here.

New password:    << Enter Root Password

Re-enter new password:    << Re-enter Root 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    << Press Y to set password
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    << Press Y to Remove Anonymous User
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    << Press Y to Disallow Remote Root Login
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    << Press Y to Remove test database
 - 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    << Press Y to Reload Privilege
Success.

All done!

Bekerja dengan Server MySQL

Masuk ke server MySQL sebagai pengguna root MySQL.

mysql -u root -p

Keluaran:

Enter password:    << Enter MySQL Root Password
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.13 Source distribution

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Instal phpMyAdmin

Jika Anda seorang pemula di MySQL dan memiliki pengetahuan yang kurang tentang baris perintah MySQL, pertimbangkan untuk menginstal phpMyAdmin, alat manajemen berbasis web sumber terbuka untuk mengelola database MySQL dan MariaDB.

BACA: Cara Instal phpMyAdmin dengan Apache di CentOS 8 / RHEL 8

BACA: Cara Instal phpMyAdmin dengan Nginx di CentOS 8 / RHEL 8

Catatan untuk MySQL 8.0 diinstal dari repositori MySQL Dev Community:

MySQL 8.0 menggunakan mekanisme caching_sha2_password untuk otentikasi yang mencegah aplikasi lama untuk mengakses database termasuk phpMyAdmin saat ini. Sederhananya, Anda tidak akan masuk ke phpMyAdmin kecuali kami menonaktifkan mekanisme kata sandi baru ini.

Anda dapat menonaktifkan mekanisme kata sandi baru secara global dengan menempatkan default-authentication-plugin=mysql_native_password di /etc/my.cnf (Pengguna yang dibuat setelah perubahan ini akan memiliki mekanisme otentikasi mysql_native_password) atau Anda dapat kembali ke otentikasi asli lama (mysql_native_password) untuk individu pengguna (Mis:root) dengan menjalankan ALTER USER 'root'@'localhost' DIIDENTIFIKASI DENGAN mysql_native_password OLEH ''; perintah di terminal MySQL.

Kesimpulan

Pada artikel ini, Anda telah mempelajari cara menginstal MySQL 8.0 di CentOS 8 / RHEL 8. Silakan bagikan tanggapan Anda di bagian komentar.


Cent OS
  1. Cara Instal MySQL di CentOS 7

  2. Cara Menginstal MySQL 8.0 di CentOS/RHEL 8

  3. Cara Menginstal MySQL 5.6 di CentOS 6.x

  1. Cara Menginstal MySQL di CentOS 8

  2. Cara menginstal phpMyAdmin di RHEL 8 / CentOS 8

  3. Cara Menginstal P7Zip di RHEL 8 / CentOS 8

  1. Cara menginstal ntfs-3g di RHEL 8 / CentOS 8

  2. Cara Menginstal PHP-mbstring di RHEL 8 / CentOS 8

  3. Cara menginstal phantomjs di RHEL 8 / CentOS 8