Nice programing

MySQL 루트 비밀번호 변경

nicepro 2020. 12. 27. 20:44
반응형

MySQL 루트 비밀번호 변경


MySQL 루트 비밀번호를 재설정하려고했습니다. mysqld_safe --skip-grant-tables를 실행하고 루트 비밀번호를 업데이트하고 사용자 테이블이 있는지 확인했습니다. mysql 데몬을 다시 시작하면 방금 설정 한 새 루트 암호로 로그인을 시도했지만 사용자 '루트'오류로 인해 액세스가 거부되었습니다. 나는 또한 mysql을 완전히 제거하고 다시 설치하려고 시도했지만 (my.cnf 파일 제거 포함) 여전히 운이 없습니다. 다음에 무엇을 할 수 있는지에 대한 제안이 있습니까?

미리 감사드립니다


SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mypass');


MySQL 참조 매뉴얼에서 이것을 살펴보십시오.

UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;

자세한 내용은이 페이지를 참조하십시오. 루트 암호 재설정 : Unix 시스템


그것을 발견! 비밀번호를 변경할 때 해시하는 것을 잊었습니다. 이 쿼리를 사용하여 문제를 해결했습니다.

update user set password=PASSWORD('NEW PASSWORD') where user='root';

잊고 PASSWORD('NEW PASSWORD')새 비밀번호를 일반 텍스트로 입력했습니다.


이것은 WAMP v3.0.6 이상에 대한 업데이트 된 답변입니다.

> UPDATE mysql.user 
> SET authentication_string=PASSWORD('MyNewPass') 
> WHERE user='root';

>FLUSH PRIVILEGES;

MySQL 버전 5.7.x에서는 mysql 테이블에 더 이상 비밀번호 필드가 없습니다. authentication_string으로 대체되었습니다.


아래 단계를 따르십시오.

1 단계. MySQL 중지

2 단계. sudo mysqld_safe --skip-grant-tables

step3.mysql -u root

step4.use mysql;

step5.show tables;

step6.describe user;

step7.update user set authentication_string=password('1111') where user='root';

비밀번호 1111로 로그인


ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

MySQL 문서에서 루트 암호 재설정 을 찾을 수 있습니다 .


비밀번호를 재설정해야합니다! Mac osx (테스트 및 작동) 및 우분투 용 단계

MySQL 중지

$ sudo /usr/local/mysql/support-files/mysql.server stop

안전 모드에서 시작하십시오.

$ sudo mysqld_safe --skip-grant-tables

(위 줄은 전체 명령입니다)

프로세스가 완료 될 때까지 계속되는 명령이므로 다른 셸 / 터미널 창을 열고 비밀번호없이 로그인합니다.

$ mysql -u root

mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';

MySQL 시작

sudo /usr/local/mysql/support-files/mysql.server start

새 비밀번호는 'password'입니다.


나도 주변을 검색했는데 어떤 상황에 맞는 답변도있을 것 같지만

내 상황은 Ubuntu 18.04.2 LTS 시스템의 Mysql 5.7입니다.

(루트 권한 얻기)

$ sudo bash

(루트 db 사용자의 비밀번호 설정 + 단계적으로 보안 구현)

# mysql_secure_installation

(소켓 대신 암호를 통해 루트 사용자에게 액세스 권한 부여)

(+ 편집 : 분명히 암호를 다시 설정해야합니까?)

( 'mySecretPassword'로 설정하지 마십시오 !!!)

# mysql -u root

mysql> USE mysql;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> set password for 'root'@'localhost' = PASSWORD('mySecretPassword'); 
mysql> FLUSH PRIVILEGES;
mysql> exit;

# service mysql restart

에 많은 감사 zetacu (그리고 에리히 용) 이 우수한 대답 (몇 시간을 검색 후 ...)

즐기세요 :-D

에스.


가끔씩 발생하는 일반적인 오류는 -p옵션을 잊어 버린 것이므로 다음을 사용 했습니까?

mysql -u root -p

MySQL 5.7에서는 비밀번호가 'authentication_string'으로 대체되었습니다.

사용하다

update user set authentication_string=password('myfavpassword') where user='root';

현재 최신 mysql 버전 (8.0.16)의 경우 이러한 답변 중 어느 것도 나를 위해 작동하지 않았습니다.

After looking at several different answers and combining them together, this is what I ended up using that worked:

update user set authentication_string='test' where user='root';

Hope this helps.


For MySQL 5.7.6 and later:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

For MySQL 5.7.5 and earlier:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

Using the mysqladmin command-line utility to alter the MySQL password:

mysqladmin --user=root --password=oldpassword password "newpassword"

Source


On MySQL 8.0.4+

To update current root user:

select current_user();
set password = 'new_password';

To update other user:

set password for 'otherUser'@'localhost' = 'new_password';

To set password policy before updating password:

set global validate_password.policy = 0;
set password = 'new_password';
set password for 'otherUser'@'localhost' = 'new_password';

Other / better way to update root password:

mysql_secure_installation

Want to stick with 5.x authentication so you can still use legacy apps?

On my.cnf

default_authentication_plugin = mysql_native_password

To update root:

set global validate_password.policy = 0;
alter user 'root'@'localhost' identified with mysql_native_password by 'new_password';

stop all wamp services , exit from wamp.

open notepad then type> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('');

then save it to c: drive with any name .. like this "c:/example.txt"

now goto your "wamp" falder wamp > bin > mysql > mysql(your version) > bin in my case path is "C:\wamp\bin\mysql\mysql5.6.17\bin"

now copy your path then run cmd with (ctrl + r) then type "cmd" (enter)

type cd then right click on cmd and paste path (enter) now type (mysqld --init-file=C:\example.txt) without braces then (enter)

then restart PC or open taskmgr and kill mysqld.exe

start wamp and your password will be removed...


For MacOS users, if you forget your root password, @thusharaK's answer(https://stackoverflow.com/a/28601069/5628856) is good, but there are a little more tricks:

If you are using system preference to start mysql serverside, simply

sudo mysqld_safe --skip-grant-tables

might not work for you.

You have to make sure the command line arguments is same with system start config.

The following command works for me:

/usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid --keyring-file-data=/usr/local/mysql/keyring/keyring --early-plugin-load=keyring_file=keyring_file.so --skip-grant-tables

You can use

ps aux | grep mysql

to check your own.


Tried the answer from @kta but didn't work for me.

I am using MySQL 8.0

This worked for me:

mysql> SET PASSWORD FOR 'root'@'localhost' = 'yourpassword'


On Ubuntu,

sudo dpkg-reconfigure mysql-server-5.5 

Replace 5.5 with your current version and you will be asked for the new root password.


So many coments, but i was helped this method:

sudo mysqladmin -u root password 'my password'

In my case after instalation i had get mysql service without a password for root user, and i was need set the password for my security.

ReferenceURL : https://stackoverflow.com/questions/7534056/mysql-root-password-change

반응형