mysql 사용자 ‘root’@ ‘localhost’에 대한 액세스 거부 수정 방법

무언가를 망치기 전에을 사용하여 로그인 $ mysql -u root -p하고 데이터베이스를 표시하십시오.

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| game_data          |
| test               |
+--------------------+

그런 다음 새 사용자를 만들려고 시도했지만 PRIVILEGES에 문제가 있음을 알았습니다.

그래서 새로운 사용자를 삭제했는데 실수로 ‘root’와 ‘Admin’을 제거했다고 생각합니다.

그런 다음 ‘root’를 다시 만들려고하지만 모든 권한을 부여 할 때 액세스 거부 오류가 발생합니다.

mysql> CREATE USER 'root'@'localhost' IDENTIFIED BY 'password';
mysql> grant all privileges on *.* to 'root'@'localhost' identified by 'password' with grant option;
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

를 사용하여 MySQL에 다시 로그인하고 $ mysql -u root -p데이터베이스를 표시하면,

+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+

다른 모든 데이터베이스는 사라졌습니다.

지금 MySQL을 어떻게 수정합니까?

데이터베이스 ‘mysql’을 찾을 수 없으며 데이터베이스를 만들거나 사용자를 만들 수 없습니다.

오류 1045 (28000) : 사용자 ‘root’@ ‘localhost’에 대한 액세스가 거부되었습니다 (암호 : YES).

MacPorts를 사용하여 MySQL을 다시 설치해야합니까? 다시 설치하면 데이터베이스가 손실됩니다 game_data.



답변

아래 단계를 따르십시오.

  1. --skip-grant-tables옵션 (보안 설정)으로 MySQL 서버 인스턴스 또는 데몬을 시작하십시오 .

    $ mysqld --skip-grant-tables
    
  2. 이 진술을 실행하십시오.

    $ mysql -u root mysql
    $mysql> UPDATE user SET Password=PASSWORD('my_password') where USER='root';
    $mysql> FLUSH PRIVILEGES;
    

위의 알 수없는 필드 비밀번호 오류가 발생하면 다음을 사용하십시오.

update user set authentication_string=password('my_password') where user='root';
  1. 마지막으로 --skip-grant-tables옵션 없이 인스턴스 / 데몬을 다시 시작하십시오 .

    $ /etc/init.d/mysql restart
    

이제 새 비밀번호로 연결할 수 있습니다.

$ mysql -u root -p

암호를 입력: my_password

MySQL “ibdata1을 잠글 수 없음”오류 수정

sudo mv /usr/local/mysql/data/ibdata1 /usr/local/mysql/data/ibdata1.bak
sudo mv /usr/local/mysql/data/ib_logfile0 /usr/local/mysql/data/ib_logfile0.bak
sudo mv /usr/local/mysql/data/ib_logfile1 /usr/local/mysql/data/ib_logfile1.bak
sudo cp -a /usr/local/mysql/data/ibdata1.bak /usr/local/mysql/data/ibdata1
sudo cp -a /usr/local/mysql/data/ib_logfile0.bak /usr/local/mysql/data/ib_logfile0
sudo cp -a /usr/local/mysql/data/ib_logfile1.bak /usr/local/mysql/data/ib_logfile1
sudo /etc/init.d/mysql restart

답변

위의 어느 것도 나를 위해 도움이되지 않았습니다. 플러그인 메소드를 지워야한다는 것을 알았습니다. 5.6에서 나는 할 수 있었다 :

sudo mysql -u root
use mysql;
[mysql] update user set plugin='' where User='root';
[mysql] flush privileges;

5.7에서 다음을 수행해야한다는 것을 알았습니다.

sudo mysql -u root
use mysql;
[mysql] update user set plugin='mysql_native_password' where User='root';
[mysql] flush privileges;

문서에 따르면 플러그인이 빈 문자열로 설정되어 있으면 기본적으로 mysql_native_password가 기본값으로 설정되어 있지만 빈 암호 해시로 인해 혼란 스러울 수 있습니다. 더 많은 뉘앙스를 보려면 https://dev.mysql.com/doc/refman/5.7/en/native-authentication-plugin.html 에서 설명서를 읽을 수 있습니다.


답변

또한 테이블의 필요한 레코드에 userplugin필드 가 있는지 확인하십시오 (예 :가있을 수 있음 "unix_socket").

버전 5.5.7부터 mysql은 다양한 인증 플러그인을 지원합니다
https://dev.mysql.com/doc/refman/5.6/en/authentication-plugins.html

따라서 비어 있지 않은 plugin필드 가 있으면 암호가 무시되고 mysql 오류 로그에 경고가 표시됩니다 (나에게는 /var/log/mysql/error.log).

[Warning] 'user' entry 'root@localhost' has both a password and an authentication plugin specified. The password will be ignored.


답변

grep 'temporary password' /var/log/mysqld.log
Sort date (newest date)

이 같은 것을 볼 수 있습니다;

[root@SERVER ~]# grep 'temporary password' /var/log/mysqld.log
2016-01-16T18:07:29.688164Z 1 [Note] A temporary password is generated for root@localhost: O,k5.marHfFu
2016-01-22T13:14:17.974391Z 1 [Note] A temporary password is generated for root@localhost: b5nvIu!jh6ql
2016-01-22T15:35:48.496812Z 1 [Note] A temporary password is generated for root@localhost: (B*=T!uWJ7ws
2016-01-22T15:52:21.088610Z 1 [Note] A temporary password is generated for root@localhost: %tJXK7sytMJV
2016-01-22T16:24:41.384205Z 1 [Note] A temporary password is generated for root@localhost: lslQDvgwr3/S
2016-01-22T22:11:24.772275Z 1 [Note] A temporary password is generated for root@localhost: S4u+J,Rce_0t
[root@SERVER ~]# mysql_secure_installation

MySQL 서버 배포 보안

Enter password for user root:

The existing password for the user account root has expired. Please set a new password.

New password:

Re-enter new password:

당신이 그것을 볼 경우

... Failed! Error: Your password does not satisfy the current policy requirements
That means your password needs to have a character such as ! . # - etc...
mix characters well, upper case, lower case, ! . , # etc...

New password:

Re-enter new password:
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
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
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? (Press y|Y for Yes, any other key for No) : Y
Success.

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.

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!
[root@SERVER ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.10 MySQL Community Server (GPL)

이 비디오 의 마지막 10 분을 보고 어떻게하는지 알려줍니다.


답변

시도 해봐:

mysql --no-defaults --force --user=root --host=localhost --database=mysql
UPDATE user SET Password=PASSWORD('NEWPASSWORD') where USER='root';
FLUSH PRIVILEGES;

답변

필자의 경우 데비안에서 mysql을 다시 시작한 후 루트 로그인에 암호가 없었습니다. 해결책은 다음과 같습니다.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'test';

다른 답변들도 native_password 플러그인에 대해 언급했지만 이것이 복잡한 조정없이 수행 할 수있는 방법입니다. 그것이 변화되는 방식입니다.