Python Manage.py SyncDB 오류
문제
Windows에서 첫 번째 Django 프로젝트를 사용하려고 시도하고 있지만 읽는 오류 메시지가 나타납니다.
File "c:\users\[username]\appdata\local\temp\easy_install-pazcre\MySQL_python-1.2.3-py2.7- win32.egg.tmp\MySQLdb\connections.py", line 187, in __init__ mysql_exceptions.OperationalError: (1045, "Access denied for user 'django_user'@'localhost' (using password: YES)")
.
명령 줄에서 데이터베이스를 다음과 같이 생성했습니다.
-- create the database
CREATE DATABASE GlobalXdb CHARACTER SET utf8;
-- create user
CREATE USER 'django_user'@'localhost' IDENTIFIED BY 'thepassword';
-- give user permissions to db
GRANT ALL ON django.* TO 'django_user'@'localhost'
.
내 settings.py
파일이 들어 있습니다 :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'GlobalXdb', # Or path to database file if using sqlite3.
'USER': 'django_user', # Not used with sqlite3.
'PASSWORD': 'thepassword', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
.
}
누구든지 내가 잘못한 일에 어떤 빛을 흘릴 수 있습니까?
해결책
데이터베이스의 이름은 globalxdb 과 아직이 라인에서 ...
.
#give user permissions to db
GRANT ALL ON django.* TO 'django_user'@'localhost'
django 이라는 데이터베이스에 django_user에 대한 사용 권한을 부여합니다.
올바른 데이터베이스 globalxdb 에 대한 사용 권한을 부여해야합니다.
다른 팁
오류 메시지는 Access denied for user 'django_user'@'localhost'
를 말하므로 내 추측은 사용자의 'django_user'가 존재하지 않거나 암호를 잘못 입력했을 것입니다.
또 다른 덜 제안은 'django_user'에 대한 권리를 확인하는 것입니다.이 사용자가 테이블을 작성할 수있는 권한이 없을 수도 있습니다.
이는 Settings.py 에서 두 개의 데이터베이스 프로파일을 정의하여 해결됩니다.
기본 - 제한된 사용 권한
sync - 사용자 root , 추가 특권을 갖는 root 로 사용됩니다.
.
DATABASES = {
'default': {
'ENGINE':'django.db.backends.mysql',
'NAME':'database_name',
'USER':'runtime',
'PASSWORD':'runtime_password',
'HOST':'',
'PORT':'',
},
'sync': {
'ENGINE':'django.db.backends.mysql',
'NAME':'database_name',
'USER':'root',
'PASSWORD':'',
'HOST':'',
'PORT':'',
},
}
MySQL의 기본 런타임 액세스에 대해 제한된 사용 권한 을 grant를 필요로합니다.
.
GRANT SELECT, INSERT, UPDATE, DELETE ON database_name.* TO 'runtime'@'localhost' IDENTIFIED BY 'runtime_password';
마지막으로 syncdb 을 실행하면 sync 액세스 프로필을 지정합니다.
.
python manage.py syncdb --database=sync
런타임에 원하는 보안과 명령 줄에서 원하는 액세스를 제공해야합니다.