GNU/Linux >> Znalost Linux >  >> Cent OS

Jak nainstalovat MySQL 8.0 na CentOS 8 / RHEL 8

MySQL je bezplatný systémový software pro správu databází, který se nejčastěji používá ve třívrstvých aplikacích k ukládání a získávání záznamů a informací.

MySQL byl původně vyvinut společností MYSQL AB, nyní ve vlastnictví Oracle Corporation. Byla to primární databázová aplikace na Linuxu, dokud se neobjevila MariaDB, fork MySQL.

V tomto článku si projdeme kroky, jak nainstalovat MySQL 8.0 na CentOS 8 / RHEL 8.

Kroky uvedené v tomto článku budou fungovat, pouze pokud jste povolili předplatné na RHEL 8 nebo nakonfigurovali místní úložiště yum ve vašem systému.

Instalace MySQL 8.0 na CentOS 8 / RHEL 8

MySQL 8.0 je k dispozici pro CentOS 8 / RHEL 8 jak z úložiště OS AppStream, tak z úložiště MySQL Dev Community. 1. Nainstalujte MySQL 8.0 z MySQL Dev Community 2. Nainstalujte MySQL 8.0 z AppStream

1. Nainstalujte MySQL 8.0 z MySQL Dev Community

Přidejte oficiální úložiště MySQL a nainstalujte komunitní server MySQL.

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

Ujistěte se, že úložiště MySQL bylo přidáno a povoleno pomocí následujícího příkazu.

dnf repolist all | grep mysql | grep enabled

Výstup:

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

Použijte příkaz dnf v CentOS/RHEL k instalaci nejnovější stabilní verze MySQL. Chcete-li nainstalovat MySQL z komunity MySQL Dev Community, dočasně deaktivujte úložiště AppStream.

### 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

Výstup:

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. Nainstalujte MySQL 8.0 z AppStream

MySQL je nyní k dispozici prostřednictvím Application Stream (Red Hat Enterprise Linux 8 pro x86_64 – AppStream (RPM)) pro RHEL 8 a CentOS 8. K instalaci serveru MySQL na RHEL 8 tedy nemusíte přidávat oficiální úložiště MySQL.

Pomocí následujícího příkazu zkontrolujte, zda je na RHEL 8 povoleno úložiště AppStream.

subscription-manager repos --list-enabled

Výstup:

+----------------------------------------------------------+
    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

Pomocí příkazu dnf nainstalujte nejnovější verzi MySQL.

dnf install -y @mysql

Výstup:

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!

Správa služby serveru MySQL

Po instalaci MySQL spusťte službu serveru MySQL pomocí následujícího příkazu.

systemctl start mysqld

Povolte server MySQL při spuštění systému.

systemctl enable mysqld

Ověřte, zda je server MySQL spuštěn pomocí následujícího příkazu.

systemctl status mysqld

Výstup:

 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.

Zabezpečený server MySQL

Nainstalováno MySQL z MySQL Dev Community

V CentOS 8 / RHEL 8 lze počáteční heslo kořenového adresáře MySQL nalézt v /var/log/mysqld.log. Pro převzetí hesla ze souboru protokolu můžete použít níže uvedený příkaz.

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

Výstup:

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

Nyní musíte spustit mysql_secure_installation pro zabezpečení instalace MySQL. Tento příkaz se stará o nastavení hesla uživatele root, odstranění anonymních uživatelů, zakázání vzdáleného přihlášení uživatele root atd.

mysql_secure_installation

Výstup:

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!

Nainstalováno MySQL z AppStream

V CentOS 8 / RHEL 8 pro uživatele root MySQL není nastaveno žádné heslo . Spustíme tedy mysql_secure_installation, abychom zabezpečili vaši instalaci MySQL nastavením hesla root, odebráním anonymních uživatelů, zakázáním vzdáleného přihlášení root atd.

mysql_secure_installation

Výstup:

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!

Práce se serverem MySQL

Přihlaste se k serveru MySQL jako uživatel root MySQL.

mysql -u root -p

Výstup:

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>

Nainstalujte phpMyAdmin

Pokud jste v MySQL nováčkem a máte menší znalosti příkazového řádku MySQL, zvažte instalaci phpMyAdmin, open source webového nástroje pro správu pro správu databází MySQL a MariaDB.

ČTĚTE: Jak nainstalovat phpMyAdmin s Apache na CentOS 8 / RHEL 8

ČTĚTE: Jak nainstalovat phpMyAdmin s Nginx na CentOS 8 / RHEL 8

Poznámky pro MySQL 8.0 nainstalované z úložiště MySQL Dev Community:

MySQL 8.0 používá pro autentizaci mechanismus caching_sha2_password, který v tuto chvíli brání starším aplikacím v přístupu k databázím včetně phpMyAdmin. Jednoduše řečeno, do phpMyAdmin se nepřihlásíte, dokud tento nový mechanismus hesel nezakážeme.

Nový mechanismus hesla můžete globálně zakázat umístěním default-authentication-plugin=mysql_native_password do /etc/my.cnf (Uživatelé vytvoření po této změně budou mít mechanismus autentizace mysql_native_password) nebo se můžete vrátit ke starému nativnímu ověřování (mysql_native_password) pro jednotlivce uživatelům (např. root) spuštěním ALTER USER 'root'@'localhost' IDENTIFIKOVANÉHO S mysql_native_password BY ''; příkaz v terminálu MySQL.

Závěr

V tomto článku jste se naučili, jak nainstalovat MySQL 8.0 na CentOS 8 / RHEL 8. Podělte se prosím o svůj názor v sekci komentářů.


Cent OS
  1. Jak nainstalovat MySQL na CentOS 7

  2. Jak nainstalovat MySQL 8.0 na CentOS/RHEL 8

  3. Jak nainstalovat MySQL 5.6 na CentOS 6.x

  1. Jak nainstalovat MySQL na CentOS 8

  2. Jak nainstalovat phpMyAdmin na RHEL 8 / CentOS 8

  3. Jak nainstalovat P7Zip na RHEL 8 / CentOS 8

  1. Jak nainstalovat ntfs-3g na RHEL 8 / CentOS 8

  2. Jak nainstalovat PHP-mbstring na RHEL 8 / CentOS 8

  3. Jak nainstalovat phantomjs na RHEL 8 / CentOS 8