Как установить сервер MySQL в Ubuntu 20.04
Если у вас возникает сложность с самостоятельной установкой и настройкой MySQL, вы можете воспользоваться готовым решением: VPS с установленным MySQL
Это руководство посвящено установке и начальной настройке сервера MySQL.
Шаг 1. Установите пакет MySQL-server и запустите установщик.
Необязательно: Обновите и установите обновления:sudo apt update && sudo apt upgrade
Do you want to continue? [Y/n] y
Установите пакет MySQL-сервера :
sudo apt install mysql-server
Do you want to continue? [Y/n] Y
Теперь запустите установщик, используя следующую команду:
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:
Шаг 1.1 - Настройте «ПОДТВЕРЖДЕНИЕ ПАРОЛЯ» (необязательно)
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.2 - Установите пароль для пользователя root
Please set the password for root here.
New password: mySecretPassword
Re-enter new password: mySecretPassword
Если вы настроили компонент «ПОДТВЕРДИТЬ ПАРОЛЬ», нажмите y .
Шаг 1.3 - Удаление анонимного пользователя (необязательно)
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
Шаг 1.4 - Настройка корневого удаленного корневого входа
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) :
Если вы хотите получить удаленный доступ отовсюду, выполните шаг 4.
Шаг 1.5 - Удалите тестовую базу данных
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.
Шаг 1.6 - Перезагрузить таблицы привилегий
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!
Шаг 2 - Отредактируйте файл конфигурации, чтобы включить удаленный доступ (необязательно)
Вам это может понадобиться, если вы хотите получить удаленный доступ к своей базе данных. Например, если вы запускаете игровой сервер на сервере A, а ваша база данных работает на сервере B, вам необходимо включить его.Откройте файл конфигурации в любом редакторе, в нашем руководстве мы используем nano .
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Найдите следующие строки и добавьте
#
в начало строк.bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
# tmpdir = /tmp
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
#mysqlx-bind-address = 127.0.0.1
Есть еще два необязательных шага:
Шаг 3 - Запретить вход в систему через командную строку без пароля.
Шаг 4 - Настроить пользователя root MySQL для удаленного доступа.
Шаг 3 - Запретить вход через командную строку без пароля (необязательно)
Войдите в MySQL-сервер как root:sudo mysql -u root
Теперь запустите этот запрос, чтобы отключить вход без пароля для пользователя root @ localhost .
Вы должны заменить
YourSuperSecretPassword
(строка 2) своим собственным безопасным паролем!ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourSuperSecretPassword';
FLUSH PRIVILEGES;
exit;
sudo service mysql restart
Если вы сейчас попытаетесь войти в систему,
sudo mysql -u root
должно произойти следующее:root@tutorial:~# sudo mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
sudo mysql -u root -p
.
Комментариев 0