Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Windows将Django项目连接到MySql?_Mysql_Django_Xampp_Sqlclient - Fatal编程技术网

如何使用Windows将Django项目连接到MySql?

如何使用Windows将Django项目连接到MySql?,mysql,django,xampp,sqlclient,Mysql,Django,Xampp,Sqlclient,我试图将Django项目连接到MySQL数据库,但遇到了一些问题。我尝试运行Xampp控制面板并在那里启动服务,但收到此错误消息 18:55:35 [mysql] Attempting to start MySQL app... 18:55:35 [mysql] Status change detected: running 18:55:39 [mysql] Status change detected: stopped 18:55:39 [mysql] Error: M

我试图将Django项目连接到MySQL数据库,但遇到了一些问题。我尝试运行Xampp控制面板并在那里启动服务,但收到此错误消息

18:55:35  [mysql]   Attempting to start MySQL app...
18:55:35  [mysql]   Status change detected: running
18:55:39  [mysql]   Status change detected: stopped
18:55:39  [mysql]   Error: MySQL shutdown unexpectedly.
18:55:39  [mysql]   This may be due to a blocked port, missing dependencies,
18:55:39  [mysql]   improper privileges, a crash, or a shutdown by another method.
18:55:39  [mysql]   Press the Logs button to view error logs and check
18:55:39  [mysql]   the Windows Event Viewer for more clues
18:55:39  [mysql]   If you need more help, copy and post this
18:55:39  [mysql]   entire log window on the forums
19:15:09  [mysql]   Problem detected!
19:15:09  [mysql]   Port 3306 in use by "Unable to open process"!
19:15:09  [mysql]   MySQL WILL NOT start without the configured ports free!
19:15:09  [mysql]   You need to uninstall/disable/reconfigure the blocking application
19:15:09  [mysql]   or reconfigure MySQL and the Control Panel to listen on a different port
我还尝试通过终端安装mysqlclient,但这导致了以下巨大错误

Collecting mysqlclient
  Using cached mysqlclient-2.0.1.tar.gz (87 kB)
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\administrator\appdata\local\programs\python\python38-32\python.exe' -u -c          
'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Administrator\\AppData\\Local
\\Temp    \\pip-install-g0c19c79\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users
\\Administrator\\AppData\\Local\\Temp\\pip-install-g0c19c79\\mysqlclient
\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', 
open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, 
__file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\Administrator\AppData\Local\Temp\pip-wheel-
er48j2t7'
   cwd: C:\Users\Administrator\AppData\Local\Temp\pip-install-g0c19c79\mysqlclient\
  Complete output (29 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win32-3.8
  creating build\lib.win32-3.8\MySQLdb
  copying MySQLdb\__init__.py -> build\lib.win32-3.8\MySQLdb
  copying MySQLdb\_exceptions.py -> build\lib.win32-3.8\MySQLdb
  copying MySQLdb\connections.py -> build\lib.win32-3.8\MySQLdb
  copying MySQLdb\converters.py -> build\lib.win32-3.8\MySQLdb
  copying MySQLdb\cursors.py -> build\lib.win32-3.8\MySQLdb
  copying MySQLdb\release.py -> build\lib.win32-3.8\MySQLdb
  copying MySQLdb\times.py -> build\lib.win32-3.8\MySQLdb
  creating build\lib.win32-3.8\MySQLdb\constants
  copying MySQLdb\constants\__init__.py -> build\lib.win32-3.8\MySQLdb\constants
  copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.8\MySQLdb\constants
  copying MySQLdb\constants\CR.py -> build\lib.win32-3.8\MySQLdb\constants
  copying MySQLdb\constants\ER.py -> build\lib.win32-3.8\MySQLdb\constants
  copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.8\MySQLdb\constants
  copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.8\MySQLdb\constants
  running build_ext
  building 'MySQLdb._mysql' extension
  creating build\temp.win32-3.8
  creating build\temp.win32-3.8\Release
  creating build\temp.win32-3.8\Release\MySQLdb
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314
\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(2,0,1,'final',0) 
-D__version__=2.0.1 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb" 
-Ic:\users\administrator\appdata\local\programs\python\python38-32\include -Ic:\users
\administrator\appdata\local\programs\python\python38-32\include "-IC:\Program Files 
(x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include" /TcMySQLdb
/_mysql.c /Fobuild\temp.win32-3.8\Release\MySQLdb/_mysql.obj /Zl /D_CRT_SECURE_NO_WARNINGS
  _mysql.c
  MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or 
directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools
\\MSVC\\14.24.28314\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2


您的问题是
设置中的
数据库
。py
,您需要安装
mysqlclient
,然后正确设置
数据库
。看看这可能是什么样子:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'someappname',
        'USER': 'username',
        'PASSWORD': 'yourpassword',
        'HOST': 'yourhost',
        'PORT': 'yourport',        
    }
}

您的问题是
设置中的
数据库
。py
,您需要安装
mysqlclient
,然后正确设置
数据库
。看看这可能是什么样子:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'someappname',
        'USER': 'username',
        'PASSWORD': 'yourpassword',
        'HOST': 'yourhost',
        'PORT': 'yourport',        
    }
}
  • 您的MySQL服务器无法启动,因为3306端口已被其他应用程序使用。所以,在启动MySQL服务之前,请检查3306端口并终止使用该端口的进程

  • 你能用.whl格式(预构建版本)下载mysqlclient并用pip安装吗

  • pip安装mysqlclient-1.3.13-cp36-cp36m-win32.whl

  • 您的MySQL服务器无法启动,因为3306端口已被其他应用程序使用。所以,在启动MySQL服务之前,请检查3306端口并终止使用该端口的进程

  • 你能用.whl格式(预构建版本)下载mysqlclient并用pip安装吗


  • pip安装mysqlclient-1.3.13-cp36-cp36m-win32.whl

    您可以添加在
    settings.py
    文件中设置的数据库设置吗?DATABASES={'default':{'ENGINE':'django.db.backends.sqlite3','NAME':os.path.join(BASE_DIR,'db.sqlite3'),}您可以添加您在
    settings.py
    文件中设置的数据库设置吗?数据库={'default':{'ENGINE':'django.db.backends.sqlite3','NAME':os.path.join(BASE_DIR,'db.sqlite3'),}}感谢您的回复。我能够打开mysql工作台并使用端口3306启动连接,因此我认为这不是问题所在。我刚刚在尝试安装时收到以下错误。whl警告:要求“mysqlclient-1.3.13-cp36-cp36m-win32.whl”看起来像文件名,但文件不存在错误:mysqlclient-1.3.13-cp36-cp36m-win32.whl在此平台上不受支持。您需要通过internet下载它。请检查此链接。谢谢你的链接。我收到一个警报,说windows无法打开这种类型的文件…请将该文件粘贴到项目根目录下,然后运行pip命令。该文件不是windows上的可执行文件,因此您无法打开或运行它。是的,我尝试过。我收到此错误消息:警告:要求“mysqlclient-1.3.13-cp36-cp36m-win32.whl”看起来像一个文件名,但该文件不存在。错误:mysqlclient-1.3.13-cp36-cp36m-win32.whl在此平台上不受支持。感谢您的回复。我能够打开mysql工作台并使用端口3306启动连接,因此我认为这不是问题所在。我刚刚在尝试安装时收到以下错误。whl警告:要求“mysqlclient-1.3.13-cp36-cp36m-win32.whl”看起来像文件名,但文件不存在错误:mysqlclient-1.3.13-cp36-cp36m-win32.whl在此平台上不受支持。您需要通过internet下载它。请检查此链接。谢谢你的链接。我收到一个警报,说windows无法打开这种类型的文件…请将该文件粘贴到项目根目录下,然后运行pip命令。该文件不是windows上的可执行文件,因此您无法打开或运行它。是的,我尝试过。我收到此错误消息:警告:要求“mysqlclient-1.3.13-cp36-cp36m-win32.whl”看起来像文件名,但该文件不存在错误:mysqlclient-1.3.13-cp36-cp36m-win32.whl在此平台上不受支持。感谢您的回复,但我尚未成功安装mysqlclient。在我的原始帖子中显示的巨大错误发生在我尝试这样做时。谢谢你的回复,但是我还没有成功安装mysqlclient。当我尝试这样做时,我在原来的帖子中显示的巨大错误发生了