> For the complete documentation index, see [llms.txt](https://enterprise-ua.hideez.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://enterprise-ua.hideez.com/korporativnii-server-hideez/rozgortannya/vstanovlennya-bazi-danikh/mysql-na-linux.md).

# MySQL на Linux

### 1. Встановлення

### *CentOS 7:*

Імпортуйте ключ перед запуском інсталятора:

```
$ sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
```

* Завантажте та встановіть:

```
$ sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm
$ sudo yum install mysql-server -y
```

* Увімкніть і запустіть службу MySQL:

```
$ sudo systemctl restart mysqld.service
$ sudo systemctl enable mysqld.service
```

* Встановлення постійного пароля root і налаштувань безпеки MySQL:

MySQL очікує, що ваш новий пароль має складатися щонайменше з 8 символів, містити великі та малі літери, цифри та спеціальні символи (не забувайте пароль, який ви встановили, він стане в нагоді пізніше). Після успішної зміни пароля на наступні запитання рекомендується відповісти «Y»:

Примітка:

* У CentOS 7, пароль root за замовчуванням може бути знайдено з використанням

```
$ sudo grep "A temporary password" /var/log/mysqld.log
```

після отримання паролю, запустіть `mysql_secure_installation`, для задання нового паролю root:

```
$ sudo mysql_secure_installation
```

Далі приклад для CentOs 7:

```
Enter password for user root:

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

  New password:
  Re-enter new password:

  Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

  Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

  Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y

  Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
```

### *Ubuntu 18.04:*

```
$ wget -c  https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb
$ sudo dpkg -i mysql-apt-config_0.8.22-1_all.deb
```

Примітка:

* натисніть "ok" для підтвердження встановлення сервера

```
$ sudo apt update
$ sudo apt install mysql-server -y
```

протягом встановлення Вам буде потрібно ввести пароль користувача MySQL. Запам'ятайте цей пароль на майбутнє.

* запустіть`mysql_secure_installation` для завершення установки:

```
$ sudo mysql_secure_installation
```

### *Ubuntu 20.04, 22.04:*

```
$ sudo apt install mysql-server -y
```

* Змініть параметри автентифікації:

```
$ sudo mysql 
```

```
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by '<mysql_root_password>';
```

Замініть `<mysql_root_password>` на сильний пароль,

Щоб вийти з консолі MySQL, натисніть Ctrl+D.

* запустіть `mysql_secure_installation` для завершення установки:

```
$ sudo mysql_secure_installation
```

### 2. Створення користувача та бази даних MySQL

2.1. Запустіть MySQL клієнт та введіть ваш client та введіть ваш root пароль MySQL

```
sudo mysql -h localhost -u root -p
```

2.2. Наступні строки створюють БД `hesdb`, користувача з іменем `hesuser` та паролем `<user_password>`. Замініть `<user_password>` на сильний пароль, інакше Ви отримаєте помилку валідації пароля.

```
mysql> CREATE DATABASE hesdb;
mysql> CREATE USER 'hesuser'@'%' IDENTIFIED BY '<user_password>';
mysql> GRANT ALL ON hesdb.* TO 'hesuser'@'%';
mysql> FLUSH PRIVILEGES;
```

Щоб вийти з консолі MySQL, натисніть Ctrl+D.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://enterprise-ua.hideez.com/korporativnii-server-hideez/rozgortannya/vstanovlennya-bazi-danikh/mysql-na-linux.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
