lution88

1142, "CREATE command denied to user 'rout'@'localhost' for table 'django_migrations'" 본문

개발일지/# 에러일지

1142, "CREATE command denied to user 'rout'@'localhost' for table 'django_migrations'"

lution88 2022. 3. 24. 15:56

vscode 로 mysql 연동하기 에러 범벅.

 

웹브라우저에서 myslq 을 다운받아서 설치하고 vscode 로 연동시켜서 migrate 를 하는데 에러가 발생했다.

최근에 파이참에서 vscode 로 넘어와서 공부하고 있는데 에러가 많이 발생해서 정신력을 많이 소모하고 있는중...

 

(.venv) PS C:\Users\lutio\Desktop\coding\django_advanced> python manage.py migrate
Life is Toooooooooooooooooooooooooooooooo Short
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions, tabom
Running migrations:
Traceback (most recent call last):
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\django\db\backends\utils.py", line 83, in _execute
    return self.cursor.execute(sql)
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\django\db\backends\mysql\base.py", line 73, in execute
    return self.cursor.execute(query, args)
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\MySQLdb\cursors.py", line 206, in execute
    res = self._query(query)
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\MySQLdb\cursors.py", line 319, in _query
    db.query(q)
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\MySQLdb\connections.py", line 254, in query
    _mysql.connection.query(self, query)
MySQLdb._exceptions.OperationalError: (1142, "CREATE command denied to user 'rout'@'localhost' for table 'django_migrations'")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\django\db\migrations\recorder.py", line 68, in ensure_schema
    editor.create_model(self.Migration)
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\django\db\backends\base\schema.py", line 357, in create_model
    self.execute(sql, params or None)
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\django\db\backends\base\schema.py", line 153, in execute
    cursor.execute(sql, params)
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\django\db\backends\utils.py", line 99, in execute
    return super().execute(sql, params)
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\django\db\backends\utils.py", line 67, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\django\db\backends\utils.py", line 76, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\django\db\utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\django\db\backends\utils.py", line 83, in _execute
    return self.cursor.execute(sql)
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\django\db\backends\mysql\base.py", line 73, in execute
    return self.cursor.execute(query, args)
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\MySQLdb\cursors.py", line 206, in execute
    res = self._query(query)
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\MySQLdb\cursors.py", line 319, in _query
    db.query(q)
  File "C:\Users\lutio\Desktop\coding\django_advanced\.venv\lib\site-packages\MySQLdb\connections.py", line 254, in query
    _mysql.connection.query(self, query)
django.db.utils.OperationalError: (1142, "CREATE command denied to user 'rout'@'localhost' for table 'django_migrations'")

migrate 실행 시 위와 같은 에러가 계속 발생하고있다.

 

에러 내용을 보면 MySQLdb._exceptions.OperationalError 라 하고, Create commad denied 라고 나오는데

MySQLdb._exceptions.OperationalError: (1142, "CREATE command denied to user 'rout'@'localhost' for table 'django_migrations'")

증상을 찾아보니 settings 의 DATABASE 에 있는 user 혹은 password 가 일치하지 않는 경우 발생한다고 나와있다.

 

확인해 보니 mysql 을 설치하고 처음 설정한 user 와 password 가 Admin 계정이 되는데

나는 db 를 하나 추가해서 새로운 user 와 새로운 password 로 진행하려고 하니 admin 계정이 아니라서

계속 명령을 거부당한 것이다.

 

그래서 settings.py 에 적어둔 DATABASE 설정을 admin 계정으로 바꾸고 migrate 를 다시 진행하니 잘 작동되는걸 확인할 수 있었다.

mysql 연동은 admin 계정으로 진행해야 한다는 걸 깨달았다.

 

Comments