Устанавливаем mariadb на CentOS 7:
# yum install -y mariadb mariadb-server
Добавляем mariadb в автозапуск:
# systemctl enable mariadb.service
Запускаем mariadb:
# systemctl start mariadb
Проверяем, запустилась или нет:
# netstat -tulnp | grep mysqld tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 22276/mysqld
Обращаю внимание, что она даже в системе отображается как сервис mysqld. Теперь запускаем стандартный скрипт настройки безопасности:
# /usr/bin/mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none):
Если вы нажали Enter, то вам будет предложено задать пароль для root-пользователя. Чтобы задать пароль введите y + Enter. Задайте новый пароль и подтвердите его.
Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success!
При установке по умолчанию, MariaDB подразумевает наличие анонимных пользователей, таким образом позволяя войти любому юзеру, даже не имеющему учетной записи. Это сделано для тестирования, при дальнейшем использовании эту возможность нужно удалить, y + Enter для удаления анонимных пользователей.
By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB 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? [Y/n] y ... Success!
Следующий шаг предложит запретить удаленный доступ для root-пользователя. Не рекомендую разрешать удаленный доступ, еще не встречалось таких ситуаций при которых он понадобился бы. Для того чтобы запретить удаленный доступ - y + Enter.
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? [Y/n] y ... Success!
По умолчанию MariaDB устанавливается с базой данных "test" для тестирования. Рекомендуется удалить ее перед началом работы. Для того чтобы удалить базу данных - y+ Enter.
By default, MariaDB 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? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success!
Теперь нужно перезагрузить привилегии, чтобы все изменения вступили в силу. Для перезагрузки привилегий - y + Enter.
Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
Файл настроек mysql/mariadb лежит в /etc/my.cnf. Для обычной работы достаточно настроек по-умолчанию. Но если вы решите изменить их, не забудьте перезапустить службу баз данных.
Перезапуск mariadb/mysql в CentOS 7:
# systemctl restart mariadb
На этом все. Базовый функционал web сервера на CentOS 7 настроен.
Проверка корневого доступа к MySQL
Теперь, если вы подключаетесь к Mysql без пароля суперпользователя, вы получаете сообщение об ошибке, что доступ запрещен.
# mysql -u root ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
# mysql -u root -p Enter password:
Кроме того, как вы видите ниже, команда показывает базы данных, что проверочная база данных теперь удалена.
MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+
Если вы хотите передать пароль в командной строке MySQL, укажите его прямо рядом с опцией -p, как показано ниже.
# mysql -u root -pMySecurePassword