CentOS 8.x 버전에서 테스트 되었지만 7.x 버전에서도 동일합니다.
mariadb 비밀번호가 기억나지 않을때 초기화 시켜주는 방법입니다.
[root@itrooms ~]# systemctl stop mariadb
[root@itrooms ~]# mysqld_safe --skip-grant-tables --skip-networking &
[1] 4185
[root@itrooms ~]# 230202 13:55:29 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
230202 13:55:29 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
먼저 mariadb 데몬을 stop 시켜줍니다.
그리고 두번째 줄의 명령어 "mysqld_safe --skip-grant-tables --skip-networking &" 를 실행하면 백그라운드로 실행되기 때문에 엔터를 한번 쳐줍니다.
mysql_secure_installation 으로 root 비밀번호를 초기화 시켜줍니다. 어디서 많이 보던 명령어죠~ ㅎ
물론 mysql -u root -p 로 접속해서 비밀번호를 변경하는 방법도 있지만 번거롭기 때문에 이 방법을 써봤습니다.
[root@itrooms ~]# 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):
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!
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!
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!
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!
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!
이제 백그라운드로 실행되고 있는 프로세서를 종료시켜줍니다.
Thanks for using MariaDB!
[root@itrooms ~]# pstree -p | grep mysql
| |-mysqld_safe(4185)---mysqld(4477)-+-{mysq+
[root@itrooms ~]# kill -9 4185 4477
[root@itrooms ~]# systemctl start mariadb
[1]+ Killed mysqld_safe --skip-grant-tables --skip-networking
그리고 systemstl start mariadb 로 다시 시작해주면 됩니다.
프로세서를 강제로 중지시켜 주지 않으면 socket 충돌로 데몬이 재실행이 되지 않습니다.
그래서 강제로 종료시켜 준것입니다.
물론 서버를 재부팅해도 되긴합니다.