[MariaDB]Table 'mysql.user' doesn't exist

HW·2023년 3월 1일
0

MariaDB

목록 보기
2/4
post-thumbnail

들어서며

MariaDB를 설정하고 이것저것 연습 해보는데 하루만에 세션을 망가트린것 같습니다.

외부 서버에서 mariaDB database로 접근하려는데 해당 database가 없다네요.

허겁지겁 root로 접속해서 보니, database들이 몽땅 날아가 있더라고요.

더불어 mysql database도 사라져있었습니다.

사실 이 에러는 실제로 Table 'mysql.user'가 존재하지 않아서 발생한게 아니라

mariaDB가 이중 실행되어 꼬여버려 발생한것이었습니다.

이 포스트는 위에 명시한 문제를 해결 하는 과정입니다.

도움이 되시길 바랍니다.

해결과정

명령어로 database를 초기화 해봤습니다.

mysql_install_db

그런데..

Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
2023-02-05 17:06:06 0 [ERROR] mysqld: Can't lock aria control file '/var/lib/mysql/aria_log_control' for exclusive use, error: 11. Will retry for 30 seconds
2023-02-05 17:06:37 0 [ERROR] mysqld: Got error 'Could not get an exclusive lock; file is probably in use by another process' when trying to use aria control file '/var/lib/mysql/aria_log_control'

대충 해석해보니 aria control 파일이 잠금 되어야 하는데

다른 곳에서 사용중이라 잠금을 하지 못하는 상태 입니다.

구글링 해보니 최신 버전의 MariaDB에서는

mysqld 자체가 mariadbd로 변경되어

mysqld 명령은 엉뚱한 버전의 다른 프로그램을 가리키고 있을 수도 있다네요.

mysql 실행중 mysql을 이중 실행하여 오류가 난 것 같습니다.

그래서 MariaDB의 서비스를 종료하려는데..

systemctl restart mariadb
Job for mariadb.service failed because the control process exited with error code.
See "systemctl status mariadb.service" and "journalctl -xe" for details.

킹능 재부팅을 해봐도 상황은 달라지지 않았습니다.

그래서

vi /etc/mysql/my.cnf

파일을 열고

skip-grant-tables 항목을 mysqld 아래에 추가해줍니다.

[mysqld]
skip-grant-tables
<...>

MariaDB를 재시작 해줍니다.

systemctl restart mariadb

그럼 다시 database를 초기화 해줍니다.

mysql_install_db
Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following command:

'/usr/bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb

You can start the MariaDB daemon with:
cd '/usr' ; /usr/bin/mysqld_safe --datadir='/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.

Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

이렇게 해도 aria control 뭐시깽이 뜨면

최후의 수단으로 mariaDB datadir를 다 삭제 해주세요.

cd /var/lib/mysql
rm -rf *

mysql_install_db
mysql_secure_installation
profile
예술융합형 개발자🎥

0개의 댓글