TIL124. Mysql 8.๋ฒ„์ „ ERROR 1045 (28000)

ID์งฑ์žฌยท2022๋…„ 2์›” 17์ผ
0

Error

๋ชฉ๋ก ๋ณด๊ธฐ
2/3
post-thumbnail

๐Ÿ“Œ ์ด ํฌ์ŠคํŒ…์—์„œ๋Š” mysql ๋กœ๊ทธ์ธ ๋ฌธ์ œ๋กœ ๋‚˜ํƒ€๋‚˜๋Š” ERROR 1045 (28000) ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์ •๋ฆฌํ•˜์˜€์Šต๋‹ˆ๋‹ค.



๐ŸŒˆ ERROR 1045 (28000)


๐Ÿค” Django ์„œ๋ฒ„๋ฅผ ๊ตฌ๋™ํ•˜๋‹ค ๋งŒ๋‚œ ๋ฌธ์ œ...

โœ”๏ธ Django ์„œ๋ฒ„๋ฅผ ๊ตฌ๋™ํ•˜๋‹ค ์ „๋‚ ๊นŒ์ง€ ๋ฉ€์ฉกํ•˜๋˜ ์„œ๋ฒ„๊ฐ€ ์ด์ƒํ•œ Error๋ฅผ ๋‚ด๋ฑ‰๊ธฐ ์‹œ์ž‘ํ–ˆ๋‹ค.

โœ”๏ธ ์‚ดํŽด๋ณด๋‹ˆ, Django์—์„œ Mysql ์„ธํŒ…์— ๊ด€ํ•œ ๋ฌธ์ œ์ธ ๊ฒƒ ๊ฐ™์•˜๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ์ฒซ ์„ธํŒ… ํ›„ ์ „ํ˜€ ๊ฑด๋“ค์ธ ์ ์ด ์—†๋‹ค.

โœ”๏ธ mysql๋กœ ์ ‘์†ํ•ด ๋ณด๋„๋ก ํ•˜์ž. ์•„๋ž˜ ๋ช…๋ น์–ด ํ›„, ๊ณ„์† ์‚ฌ์šฉํ•˜๋˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ–ˆ๋Š”๋ฐ, ์•„๋ž˜์™€ ๊ฐ™์€ Eroor๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.

$ > mysql -u root -p

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

โœ”๏ธ ์ฐพ์•„๋ณด๋‹ˆ, ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ํ‹€๋ ธ๋‹ค๊ณ ํ•œ๋‹ค. ๋„ˆ๋ฌด์–ต์šธํ–ˆ์ง€๋งŒ ๋ฐฉ๋ฒ•์ด์—†๋‹ค. ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋ฐ”๊ฟ”์•ผ๊ฒ ๋‹ค.

๐Ÿค” ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ฐ”๊พธ๊ธฐ ์‹คํŒจ ๊ณผ์ •

โœ”๏ธ mysql ๋น„๋ฐ€๋ฒˆํ˜ธ ์žฌ์„ค์ • ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์ฐพ์•„๋ณด๋‹ˆ, ์•„๋ž˜์™€ ๊ฐ™์€ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ผ ๋‚˜์˜จ๋‹ค.

โœ”๏ธ ์šฐ์„  ์•„๋ž˜์™€ ๊ฐ™์ด ์ž…๋ ฅ ํ›„, ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜๋ผํ•˜๋ฉด ๊ทธ๋ƒฅ ๋ฐ”๋กœ Enter๋ฅผ ๋ˆŒ๋Ÿฌ ์ง„์ž…ํ•œ๋‹ค.

$ > mysql -u root -p
$ > Enter password:

โœ”๏ธ mysql์„ ์ง€์ • ํ›„, root์˜ ๋น„๋ฐ€๋ฒˆ๋ฅผ 1234๋กœ ๋ฐ”๊พธ๋Š” ๋ช…๋ น์–ด๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค๊ณ ํ•ด์„œ ์‹œ๋„ํ–ˆ๋‹ค.

mysql > use mysql;
mysql > UPDATE user set password=password("1234") where user = 'root';

โœ”๏ธ ERROR 1064 (42000) ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. ์•„๋ฌด๋ฆฌ๋ด๋„ ๋ฌธ๋ฒ•์ ์œผ๋กœ ํ‹€๋ฆฐ ๊ณณ์„ ์ฐพ์„ ์ˆ˜๊ฐ€ ์—†๋Š”๋ฐ ๋ชจ๋‘ ๋ฌธ๋ฒ•์ด ํ‹€๋ ค์„œ ๋‚˜์˜จ๊ฑฐ๋ผ ํ•œ๋‹ค.

โœ”๏ธ near ๋’ท๋ถ€๋ถ„์— ์ฐํžŒ ๊ณณ์ด ๊ทธ ๊ฐ€๋Šฅ์„ฑ์„ ๋‚˜ํƒ€๋‚ด๋Š” ๋ถ€๋ถ„์ธ๋ฐ,, ๋‹ค๋ฅธ์‚ฌ๋žŒ๋“ค์€ ์ด๋ ‡๊ฒŒ ๋ซ๋‹คํ•ด์„œ ์–ด๋””์„œ๋ถ€ํ„ฐ ์ž˜๋ชป๋˜์—ˆ๋Š”์ง€ ์ฐพ๊ธฐ ์‹œ์ž‘ํ–ˆ๋‹ค.

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '("1234") where user = 'root'' at line 1

๐Ÿค” ๋น„๋ฐ€๋ฒˆํ˜ธ ์„ฑ๊ณต ๊ณผ์ •

โœ”๏ธ ๊ณ„์† ์ฐพ์•„๋ณด๋‹ˆ, mysql ๋ฒ„์ „์ด ๋ฐ”๋€Œ๋ฉด์„œ ๋ช…๋ น์–ด๊ฐ€ ์ˆ˜์ •๋˜์—ˆ๋‹ค๊ณ  ํ•œ๋‹ค.

โœ”๏ธ ์šฐ์„  ๋‚ด ๋ฒ„์ „์— ๋งž๋Š” ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฒ„์ „๋ถ€ํ„ฐ ํ™•์ธํ•œ๋‹ค. 8๋ฒ„์ „์ด๋ผ ๋‚˜์˜จ๋‹ค.

mysql> SELECT VERSION();

โœ”๏ธ 8.xx ๋ฒ„์ „์ผ ๊ฒฝ์šฐ, ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ณ€๊ฒฝ ๋ช…๋ น์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค. ๋งˆ์ง€๋ง‰์— flush๋ฅผ ๊ผญ ํ•ด์ฃผ์–ด์•ผ ๋œ๋‹ค.

mysql> use mysql;
Query OK, 0 rows affected (0.00 sec)

mysql> alter user 'root'@'localhost' identified with mysql_native_password by '1234';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

profile
Keep Going, Keep Coding!

0๊ฐœ์˜ ๋Œ“๊ธ€