django를 mysql와 연동하기 위한 첫 삽을 뜨려고 하는데 그 과정에서 껵게된 오류를 나열하고 해결법을 정리해 보았습니다.
개린이의 개발자 한걸음이 차아아암~~ 쉽지 않네요.
아래와 같은 오류를 만났습니다.
당황 스럽지만 너무 걱정마세요. 우린 금수저로 태어나지 못한 오류를 이미 갖고 있는데. 이정도 오류는 오류 축에 끼지도 못하는거 아니겠습니까?
어쨋든 쑤댁오바형님에게 물어 봐야겠조?
django.db.utils.OperationalError: (2059, "Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory")</code></pre>
다시 돌아와서 그렇다면 내가 하려했던게 뭔지 다시 파악해야 겠조?
./manage.py makemigrations
명령어를 사용하다가 오류에 직면했쥬?!2번 해결책을 사용하는게 더 간단할 수 있을것 같아요.
여기서부터는 mysql CLI를 사용하는 만큼 쿼리문을 알아야해요. 몰라도 그냥 따라하세요.
처음부터 준비되고 알고 시작하는 금수저들은 많지 않아요.
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select user, host from user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| analyzer | % |
| root | 127.0.0.1 |
| root | ::1 |
| debian-sys-maint | localhost |
| root | localhost |
+------------------+-----------+
5 rows in set (0.00 sec)
제가 아래에 적어 놓은 유저 생성 방법을 참고해서 작성해주세요.
가장 중요한 포인트는 아래 쿼리문 중에
mysql_native_password
이 단어를 설정해 주어야해요. 오류가 난게 바로 이 부분에 caching_sha2어쩌구 저쩌구가 적혀 있어서 그래요. 맞나?! 네 맞을 거에요.
ALTER user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '변경할비밀번호';
관리자 권한 명령 프롬프트 실행
MySQL 5.7 버전 이상
mysql -u root -p
mysql database 선택하고 host, user 정보 확인
mysql> use mysql;
mysql> select host,user,authentication_string from user;
host 종류는 'localhost'와 '%'가 있다. 기본적으로 MySQL을 설치하면 로컬(localhost)에서만 접속이 가능하고 외부에서는 접속이 불가능하게 되어 있다.
따라서, root계정의 외부접속을 허용하려면 다음과 같은 쿼리를 날리면 된다.
mysql> inster into mysql.user (host, user, authentication_string, ssl_cipher, x509_issuer, x509_subject) values ('%','사용자명', password('비밀번호'),'','','');
mysql> grant all privileges on *.* to 'root'@'%';
mysql> flush privileges;
외부 접속 허용과 동일한 루틴으로 사용자 추가도 진행 할 수 있다.
create user 'test'@'localhost' identified by 'test1234';
or
mysql> inster into mysql.user (host, user, authentication_string, ssl_cipher, x509_issuer, x509_subject) values ('% or localhost','사용자명', password('비밀번호'),'','','');
mysql> grant all privileges on *.* to 'root'@'% or localhost';
mysql> flush privileges;
mysql> drop user '사용자 ID';
또는mysql> delete from user where user = '사용자 ID';
mysql> grant all privileges on dbname.table to userid@host identified by 'password';
mysql> grant select, insert, update on dbname.table to userid@host identified by 'password';
mysql> grant select, insert, update on dbname.table to userid@'192.169.%' identified by 'password';
dbname.table 대신 dbname.* 은 해당 database의 모든 table의 접근을 허용한다. *.*은 모든 접근을 가능하게 한다.
mysql> flush privileges;
mysql> revoke all on dbname.table from username@host;
mysql> show grants for userid@host;
mysql> show grants for 'njkim'@'%';
mysql> use mysql;
Database changed
mysql> update user set password=PASSWORD('변경할 비밀번호') where user='사용자이름';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> delete from user where user='USER_ID';
mysql> flush privileges;
mysql> delete from user where user='test';
Query OK, 1 row affected (0.00 sec)
mysql> delete from user where user='test_grant';
Query OK, 2 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)