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

Jak nainstalovat Mysql 8 na Rocky Linux/Centos 8

Mysql se běžně instaluje jako součást oblíbeného zásobníku LAMP nebo LEMP (Linux, Apache/Nginx, MySQL/MariaDB, PHP/Python/Perl). Implementuje relační model a strukturovaný dotazovací jazyk (SQL) pro správu a dotazování dat.

V této příručce nainstalujeme mysql 8 na Centos 8. Tato příručka funguje také na jiných derivátech RHEL 8, jako je Rocky Linux 8 a Alma Linux 8

Související příspěvky:

  • Jak nainstalovat a nakonfigurovat Mysql Server 8 na Fedoře 34/35
  • Jak nainstalovat a nastavit mysql 8 na Ubuntu 20.04
  • Jak spustit Mysql 8 pomocí Docker a Docker-Compose
  • Použití Ansible k instalaci a inicializaci Mysql 8 na Centos 8

Požadavky

  • Aktualizovaný server Centos 8
  • Kořenový přístup k serveru nebo uživatel s přístupem sudo
  • Přístup k internetu ze serveru

Obsah

  1. Ujistěte se, že je server aktuální
  2. Instalace serveru mysql

Aktualizace systému

Než budete pokračovat, ujistěte se, že je váš systém aktuální pomocí tohoto příkazu:

sudo dnf -y update

Instalace serveru mysql

Pomocí tohoto příkazu vyhledejte, které balíčky poskytují mysql-server:

$ sudo dnf search mysql-server

Last metadata expiration check: 1:03:33 ago on Tue 17 Aug 2021 11:20:55 AM UTC.
==================================================== Name Exactly Matched: mysql-server ====================================================
mysql-server.x86_64 : The MySQL server and related files

Pojďme zkontrolovat informace o balíčku, který jsme našli výše, pomocí tohoto příkazu:

$ sudo dnf info mysql-server
Last metadata expiration check: 1:04:00 ago on Tue 17 Aug 2021 11:20:55 AM UTC.
Installed Packages
Name         : mysql-server
Version      : 8.0.21
Release      : 1.module_el8.2.0+493+63b41e36
Architecture : x86_64
Size         : 108 M
Source       : mysql-8.0.21-1.module_el8.2.0+493+63b41e36.src.rpm
Repository   : @System
From repo    : appstream
Summary      : The MySQL server and related files
URL          : http://www.mysql.com
License      : GPLv2 with exceptions and LGPLv2 and BSD
Description  : MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
             : client/server implementation consisting of a server daemon (mysqld)
             : and many different client programs and libraries. This package contains
             : the MySQL server and some accompanying files and directories.

Nyní pojďme nainstalovat mysql-server balíček:

sudo dnf install -y mysql-server

Výstup:

$ sudo dnf install -y mysql-server
Last metadata expiration check: 0:44:57 ago on Tue 17 Aug 2021 11:20:55 AM UTC.
Dependencies resolved.
======================================================================================================
 Package                       Arch      Version                                   Repository    Size
======================================================================================================
Installing:
 mysql-server                  x86_64    8.0.21-1.module_el8.2.0+493+63b41e36      appstream     22 M
Installing dependencies:
 libaio                        x86_64    0.3.112-1.el8                             baseos        33 k
 mariadb-connector-c-config    noarch    3.1.11-2.el8_3                            appstream     15 k
 mecab                         x86_64    0.996-1.module_el8.2.0+493+63b41e36.9     appstream    393 k
 mysql                         x86_64    8.0.21-1.module_el8.2.0+493+63b41e36      appstream     12 M
 mysql-common                  x86_64    8.0.21-1.module_el8.2.0+493+63b41e36      appstream    148 k
 mysql-errmsg                  x86_64    8.0.21-1.module_el8.2.0+493+63b41e36      appstream    581 k
 perl-Carp                     noarch    1.42-396.el8                              baseos        30 k
 perl-Data-Dumper              x86_64    2.167-399.el8                             baseos        58 k
 perl-Digest                   noarch    1.17-395.el8                              appstream     27 k
 perl-Digest-MD5               x86_64    2.55-396.el8                              appstream     37 k
 perl-Encode                   x86_64    4:2.97-3.el8                              baseos       1.5 M
 perl-Errno                    x86_64    1.28-419.el8_4.1                          baseos        76 k
 perl-Exporter                 noarch    5.72-396.el8                              baseos        34 k
 perl-File-Path                noarch    2.15-2.el8                                baseos        38 k
 perl-File-Temp                noarch    0.230.600-1.el8                           baseos        63 k
 perl-Getopt-Long              noarch    1:2.50-4.el8                              baseos        63 k
 perl-HTTP-Tiny                noarch    0.074-1.el8                               baseos        58 k
 perl-IO                       x86_64    1.38-419.el8_4.1                          baseos       142 k
 perl-MIME-Base64              x86_64    3.15-396.el8                              baseos        31 k
 perl-Net-SSLeay               x86_64    1.88-1.module_el8.3.0+410+ff426aa3        appstream    379 k
 perl-PathTools                x86_64    3.74-1.el8                                baseos        90 k
 perl-Pod-Escapes              noarch    1:1.07-395.el8                            baseos        20 k
 perl-Pod-Perldoc              noarch    3.28-396.el8                              baseos        86 k
 perl-Pod-Simple               noarch    1:3.35-395.el8                            baseos       213 k
 perl-Pod-Usage                noarch    4:1.69-395.el8                            baseos        34 k
 perl-Scalar-List-Utils        x86_64    3:1.49-2.el8                              baseos        68 k
 perl-Socket                   x86_64    4:2.027-3.el8                             baseos        59 k
 perl-Storable                 x86_64    1:3.11-3.el8                              baseos        98 k
 perl-Term-ANSIColor           noarch    4.06-396.el8                              baseos        46 k
 perl-Term-Cap                 noarch    1.17-395.el8                              baseos        23 k
 perl-Text-ParseWords          noarch    3.30-395.el8                              baseos        18 k
 perl-Text-Tabs+Wrap           noarch    2013.0523-395.el8                         baseos        24 k
 perl-Time-Local               noarch    1:1.280-1.el8                             baseos        34 k
 perl-URI                      noarch    1.73-3.el8                                appstream    116 k
 perl-Unicode-Normalize        x86_64    1.25-396.el8                              baseos        82 k
 perl-constant                 noarch    1.33-396.el8                              baseos        25 k
 perl-interpreter              x86_64    4:5.26.3-419.el8_4.1                      baseos       6.3 M
 perl-libnet                   noarch    3.11-3.el8                                appstream    121 k
 perl-libs                     x86_64    4:5.26.3-419.el8_4.1                      baseos       1.6 M
 perl-macros                   x86_64    4:5.26.3-419.el8_4.1                      baseos        72 k
 perl-parent                   noarch    1:0.237-1.el8                             baseos        20 k
 perl-podlators                noarch    4.11-1.el8                                baseos       118 k
 perl-threads                  x86_64    1:2.21-2.el8                              baseos        61 k
 perl-threads-shared           x86_64    1.58-2.el8                                baseos        48 k
 protobuf-lite                 x86_64    3.5.0-13.el8                              appstream    149 k
Installing weak dependencies:
 perl-IO-Socket-IP             noarch    0.39-5.el8                                appstream     47 k
 perl-IO-Socket-SSL            noarch    2.066-4.module_el8.3.0+410+ff426aa3       appstream    298 k
 perl-Mozilla-CA               noarch    20160104-7.module_el8.3.0+416+dee7bcef    appstream     15 k
Enabling module streams:
 mysql                                   8.0
 perl                                    5.26
 perl-IO-Socket-SSL                      2.066
 perl-libwww-perl                        6.34

Transaction Summary
======================================================================================================
Install  49 Packages

Total download size: 48 M
Installed size: 218 M
Downloading Packages:

...
Complete!

Výše uvedený příkaz a výstup nainstaluje mysql-server do naší instance Centos 8.

Spuštění a povolení služby mysql

Po instalaci. služba nebude ve výchozím nastavení povolena ani spuštěna.
Stav můžeme zkontrolovat pomocí tohoto příkazu:

sudo systemctl status mysqld

Spusťte službu:

sudo systemctl start mysqld

Výstup:

$ sudo systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-08-17 12:11:09 UTC; 35s ago
  Process: 70489 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 70363 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
  Process: 70338 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
 Main PID: 70445 (mysqld)
   Status: "Server is operational"
    Tasks: 39 (limit: 23800)
   Memory: 427.0M
   CGroup: /system.slice/mysqld.service
           └─70445 /usr/libexec/mysqld --basedir=/usr

Aug 17 12:10:58 db-server.citizix.com systemd[1]: Starting MySQL 8.0 database server...
Aug 17 12:10:58 db-server.citizix.com mysql-prepare-db-dir[70363]: Initializing MySQL database
Aug 17 12:11:09 db-server.citizix.com systemd[1]: Started MySQL 8.0 database server.

Povolte službu, aby se vždy spustila při restartování serveru pomocí tohoto příkazu:

sudo systemctl enable mysqld

Chcete-li zobrazit protokol služby MySQL 8 pomocí příkazu journalctl, postupujte takto:

$ sudo journalctl -u mysqld -xe
$ sudo tail -f /var/log/mysql/mysqld.log

Zabezpečení MySQL

MySQL obsahuje bezpečnostní skript, který vám umožňuje změnit některé výchozí možnosti konfigurace za účelem zlepšení zabezpečení MySQL.

Chcete-li použít bezpečnostní skript, spusťte následující příkaz:

sudo mysql_secure_installation

To vás provede řadou výzev s dotazem, zda chcete provést určité změny v možnostech zabezpečení instalace MySQL. Mezi tyto možnosti patří:

  • nastavení hesla uživatele root
  • povolení KOMPONENTY OVĚŘENÍ HESLA, která zajistí použití silných hesel
  • Odebrání anonymních uživatelů
  • Zakázání vzdáleného přihlášení root
  • Odebrání testovacích databází

Zde je ukázkový výstup z mého serveru:

$ sudo mysql_secure_installation

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

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
Please set the password for root here.

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!

Testování instalace MySQL

Zkontrolujeme verzi mysql pomocí tohoto příkazu:

mysql -V

Nyní se můžete přihlásit jako root uživatele a výše uvedené heslo.

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.21 Source distribution

Copyright (c) 2000, 2020, 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> select version();
+-----------+
| version() |
+-----------+
| 8.0.21    |
+-----------+
1 row in set (0.00 sec)

mysql>

Závěr

Podařilo se nám nainstalovat mysql v této příručce.


Cent OS
  1. Jak debootstrap na CentOS Linux

  2. Jak nainstalovat PostgreSQL na CentOS 8 / Rocky Linux 8 / RHEL 8

  3. Jak nainstalovat klienta FreeIPA na Rocky Linux/Alma Linux/CentOS 8

  1. Jak nainstalovat a nakonfigurovat Redis 6 na Rocky Linux/Centos 8

  2. Jak nainstalovat Java 17 na Rocky Linux 8/Centos 8

  3. Jak nainstalovat Erlang na Rocky Linux/Alma Linux/CentOS 8

  1. Jak nainstalovat MySQL na CentOS 7

  2. Jak nainstalovat MySQL Workbench na Rocky Linux 8

  3. Jak nainstalovat MySQL 5.6 na CentOS 6.x