mysql의 기본 'mysql' 데이터베이스를 복구/재생성하는 방법
제가 mysql을 설치했을 때, 그것은 mysql과 information schema라는 두 개의 데이터베이스와 함께 왔습니다.제가 실수로 mysql 데이터베이스를 삭제했습니다.제가 그것을 재현할 수 있는 방법이 있을까요?
또한 사용자 정보가 포함된 표가 포함되어 있기 때문에 사용자 정보를 보지 않고 볼 수 있는 방법은 없을까요?
아직 로그인이 가능하고(사용자 테이블이 없기 때문에 그렇지 않다고 가정합니다) 저장할 데이터베이스가 있는 경우 다음과 같이 덤프합니다.
mysqldump --routines databasename > outfile.sql
명령을 사용하여 MySQL 데이터베이스를 다시 만들 수 있습니다.
# Most MySQL versions
mysql_install_db
# MySQL 5.7 and later
mysqld --initialize
자세한 내용은 다음 사이트에서 확인할 수 있습니다.
Windows에서는 다음 명령 중 하나를 사용합니다.
C:\> bin\mysqld --initialize
C:\> bin\mysqld --initialize-insecure
최근에 mysql 8을 설치했는데 mysql 기본 데이터베이스에 문제가 있는 것 같습니다.어쨌든, 이것은 저에게 효과가 있었습니다.
mysql_upgrade -u root -p
다음 오류가 발생했습니다.
root@ubuntu-2gb-nbg1-1 ~ # mysqld --initialize
2019-01-23T15:11:22.428139Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-01-23T15:11:22.435428Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2019-01-23T15:11:22.435653Z 0 [ERROR] Aborting
솔루션(이렇게 하면 모든 데이터베이스와 테이블이 삭제되고 백업이 가능합니다!)
/etc/init.d/mysql stop
rm /var/lib/mysql -rf
mkdir /var/lib/mysql
chown mysql:mysql /var/lib/mysql
mysqld --initialize
이제 추가skip-grant-tables
당신의/etc/mysql/mysql.conf.d/mysqld.cnf
, 루트 비밀번호가 유효하지 않기 때문에 어떻게든 로그인하여 새 비밀번호를 설정해야 합니다.
/etc/init.d/mysql start
mysql
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql;
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| engine_cost |
| event |
| func |
| general_log |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
31 rows in set (0.00 sec)
이제 사용자 테이블이 있는 새 mysql 데이터베이스가 있지만 암호는 "messed up"입니다.따라서 유효한 암호를 설정해야 합니다.
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('somepass');
FLUSH PRIVILEGES;
ctrl+d
이제 제거합니다.skip-grant-tables
사용자의 설정에서, 그렇지 않으면 설정이 경우 안전하지 않습니다.
이제 "정상적으로" 로그인할 수 있습니다.mysql -u root -p
(입력)somepass
)
제가 실수로 데이터베이스 mysql을 제거했는데 mysql --initialize가 도움이 되지 않았습니다.오류가 나타나지 않았고, mysql 서비스도 정상적으로 시작했지만, 폴더 mysql이 생성되지 않았고, mysql을 사용할 수 없었습니다 - 새로운 데이터베이스를 생성할 수도 없었습니다.
여러 가지 옵션을 시도하는 데 많은 시간을 들인 결과, 제 sqld를 충돌시킨 nodb_additional_mem_pool_size=20M의 옵션이 더 이상 사용되지 않음을 알게 되었습니다. --initialize
mysql config를 수정한 후 잘 작동했습니다.
비슷한 문제가 있었습니다. 백업 및 복원 작업 중에 mysql 및 information_schema 데이터베이스를 삭제했습니다.자체 데이터베이스를 복원한 후에는 시스템 테이블이 복원되지 않았기 때문에 사용자를 생성하거나 실제로 수행할 수 없었습니다.(물론 우리도 회사의 생산 환경에서는 절대로 그런 일을 하지 않을 것입니다.)
(우리가 했던 것처럼) 이전 mysql_install_db의 복사본이 여전히 있는 경우 사용하지 마십시오.MySQL 5.6.8부터 펄 스크립트입니다.mysqld_safe와 유사한 옵션을 사용합니다. 우리에게 잘 작동했습니다. 복원된 DB에서 InnoDB 복구를 실행하고, 시스템 데이터베이스를 설치하고, 슬레이브 서버를 다시 실행했습니다.
macOS에서
OS: macOS 몬테레이
칩 : 애플 M1
해결책
파일 경로가 다를 수 있습니다. 검토 부탁드립니다!
mysql 서비스를 중지합니다.
brew services stop mysql
Mysql 데이터 디렉토리 제거:
rm -r /opt/homebrew/var/mysql
새 Mysql 데이터 디렉토리 생성:
mkdir /opt/homebrew/var/mysql
Mysql 데이터 디렉토리 초기화:
mysqld --initialize
더하다
skip-grant-tables
철통같이/opt/homebrew/etc/my.cnf
암호 없이 Mysql 서버에 연결할 수 있도록 허용합니다.Mysql 서비스를 시작합니다.
brew services start mysql
Mysql 클라이언트 실행:
mysql
Mysql 클라이언트에서 다음 명령을 실행합니다.
use mysql; # switch to mysql database
FLUSH PRIVILEGES;
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('<new-password>');
FLUSH PRIVILEGES;
제거한다.
skip-grant-tables
파일에서/opt/homebrew/etc/my.cnf
그런 다음 서비스를 다시 시작합니다.
brew services restart mysql
새 암호로 Mysql 클라이언트에 로그인합니다.
mysql -u root -p
명령 요약
brew services stop mysql
rm -r /opt/homebrew/var/mysql
mkdir /opt/homebrew/var/mysql
mysqld --initialize
# Add skip-grant-tables to /opt/homebrew/etc/my.cnf
brew services start mysql
mysql
# Run on mysql: use mysql; # switch to mysql database
# Run on mysql: FLUSH PRIVILEGES;
# Run on mysql: SET PASSWORD FOR 'root'@'localhost' = PASSWORD('<new-password>');
# Run on mysql: FLUSH PRIVILEGES;
# Run on mysql: exit;
# Remove `skip-grant-tables` from `/opt/homebrew/etc/my.cnf`
brew services restart mysql
mysql -u root -p
Windows 10에서 MariaDB를 실행하는데 "table mysql.column_stats의 잘못된 정의"라는 오류가 발생했습니다.그래서 MariaDB 데이터베이스를 다시 만들어야 할 때라고 판단했습니다.
- 데이터 백업/내보내기, 사용자 및 할당된 권한 기록
- 데이터베이스 서비스를 중지합니다.
net stop mysql
cd c:\Program Files\MariaDB 10.8\bin
mariadb-install-db.exe --datadir=C:\some\dirs\data\ --password ...
- 데이터베이스 서비스를 다시 시작하는 것을 잊지 마십시오.
net start mysql
- 데이터를 다시 가져오기
- 사용자 다시 생성 및 assign 다시 생성 권한
언급URL : https://stackoverflow.com/questions/8911115/how-to-recover-recreate-mysqls-default-mysql-database
'programing' 카테고리의 다른 글
빈 패키지 정의(공용 구성원 없음) (0) | 2023.10.26 |
---|---|
실행 중인 도커 컨테이너의 IP 주소를 가져오는 방법 (0) | 2023.10.26 |
엑셀 라이브러리로 엑셀 파일의 셀 스타일을 변경하려면 어떻게 해야 합니까? (0) | 2023.10.21 |
인수가 지원되는 사용자 지정 wp.media (0) | 2023.10.21 |
MySQL에서 지정된 행 번호로 시작하는 행을 선택하려면 어떻게 해야 합니까? (0) | 2023.10.21 |