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

Jak nainstalovat MySQL 8.0/5.7 na CentOS 7 / RHEL 7

MySQL je bezplatný a otevřený systém pro správu databází, běžně používaný ve webový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 pro operační systém Linux, dokud se neobjevila MariaDB, fork MySQL.

V tomto článku uvidíme, jak nainstalovat MySQL 8.0/5.7 na CentOS 7 / RHEL 7.

Přidat úložiště MySQL

MySQL již není distribuován prostřednictvím repozitářů OS. K instalaci komunitního serveru MySQL byste tedy museli přidat oficiální úložiště MySQL.

rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-4.noarch.rpm

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

yum repolist all | grep mysql | grep enabled

Výstup:Může vypadat.

mysql-connectors-community/x86_64   MySQL Connectors Community   enabled:    221
mysql-tools-community/x86_64        MySQL Tools Community        enabled:    135
mysql80-community/x86_64            MySQL 8.0 Community Server   enabled:    301

Nainstalujte komunitní server MySQL

Oracle aktuálně nabízí obě stabilní verze (v8.0 a v5.7). Můžete si vybrat ten, který chcete nainstalovat do svého počítače.

Nainstalujte MySQL 8.0

Pomocí příkazu yum nainstalujte komunitní server MySQL 8.0.

yum install -y mysql-community-server

Nainstalujte MySQL 5.7

Pokud chcete vyzkoušet starší verzi MySQL, nainstalujte si MySQL 5.7 na svůj počítač pomocí níže uvedeného příkazu.

yum install -y mysql-community-server --disablerepo=mysql80-community --enablerepo=mysql57-community

Po instalaci MySQL můžete spustit MySQL server pomocí následujícího příkazu.

systemctl start mysqld

Poté povolte automatické spouštění služby MySQL při startu systému.

systemctl enable mysqld

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

systemctl status mysqld

Počáteční heslo kořenového adresáře MySQL

V CentOS/RHEL najdete počáteční heslo root MySQL 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-11-27T08:27:27.063799Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: PJyCjhTjP1:n

Zabezpečený server MySQL

Nyní musíte spustit mysql_secure_installation pro zabezpečení vaší 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 initital MySQL root password

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

New password:  << Enter new MySQL root password

Re-enter new password:  << Re-enter new MySQL 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 as we have already set new 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  << Type Y to remove anonymous users
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  << Type Y to 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  << Type 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  << Type Y to reload privilege tables
Success.

All done!

Práce se serverem MySQL

Přihlaste se k serveru MySQL pomocí uživatele root a jeho hesla.

mysql -u root -p

Výstup:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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

phpMyAdmin je open-source webový nástroj pro správu pro správu databází MySQL a MariaDB. Pomocí níže uvedeného odkazu nainstalujte a nakonfigurujte phpMyAdmin na základě vašeho operačního systému.

ČTĚTE:Nainstalujte phpMyAdmin na CentOS 7 / RHEL 7

Závěr

To je vše. Doufám, že jste se naučili, jak nainstalovat MySQL 8.0/5.7 na CentOS 7 / RHEL 7.


Cent OS
  1. Zakázat SELinux na CentOS nebo RHEL 5/5.1/5.2/5.3/5.4/5.5/5.6/5.7

  2. Jak nainstalovat Apache, MySQL, PHP (LAMP) na CentOS/RHEL 7

  3. Jak nainstalovat MySQL 8.0 na CentOS/RHEL 8

  1. Jak nainstalovat MySQL na CentOS 7

  2. Jak nainstalovat MySQL na CentOS 7.x?

  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