Làm cách nào để cài đặt máy khách MySQL bằng pip?

Tôi đã thử một số giải pháp được đăng ở đây nhưng không gặp may. Tuy nhiên, tôi có thể kết nối với mysql bằng lệnh ‘mysql -u root - p’ mà không gặp vấn đề gì sau khi thay đổi đường dẫn bằng cách làm theo giải pháp được cung cấp trong diễn đàn này

[storefront-yT6GZW6h] C:\Users\Pua Hoover\Desktop\storefront>mysql -u root -p
Enter password: *********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 49
Server version: 8.0.28 MySQL Community Server - GPL

Copyright [c] 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Tôi đang sử dụng phiên bản Window 10 Home và python 3. 8. 2 trong pipenv. Thông báo lỗi tôi nhận được như bên dưới

[storefront-yT6GZW6h] C:\Users\Pua Hoover\Desktop\storefront>pipenv install mysqlclient
Installing mysqlclient...
Error:  An error occurred while installing mysqlclient!
Error text: Collecting mysqlclient
  Using cached mysqlclient-2.1.0.tar.gz [87 kB]
  Preparing metadata [setup.py]: started
  Preparing metadata [setup.py]: finished with status 'done'
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient [setup.py]: started
  Building wheel for mysqlclient [setup.py]: finished with status 'error'
  Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient: started
  Running setup.py install for mysqlclient: finished with status 'error'

  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [31 lines of output]
      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
      warning: build_py: byte-compiling is disabled, skipping.

      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\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -Dversion_info=[2,1,0,'final',0] -D__version__=2.1.0 "-IC:\Program Files [x86]\MariaDB\MariaDB Connector C\include\mariadb" "-IC:\Program Files [x86]\MariaDB\MariaDB Connector C\include" "-IC:\Users\Pua Hoover\.virtualenvs\storefront-yT6GZW6h\include" "-Ic:\users\pua hoover\appdata\local\programs\python\python38-32\include" "-Ic:\users\pua hoover\appdata\local\programs\python\python38-32\Include" "-IC:\Program Files [x86]\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include" "-IC:\Program Files [x86]\Windows Kits\10\include\10.0.16299.0\ucrt" "-IC:\Program Files [x86]\Windows Kits\10\include\10.0.16299.0\shared" "-IC:\Program Files [x86]\Windows Kits\10\include\10.0.16299.0\um" "-IC:\Program Files [x86]\Windows Kits\10\include\10.0.16299.0\winrt" "-IC:\Program Files [x86]\Windows Kits\10\include\10.0.16299.0\cppwinrt" /TcMySQLdb/_mysql.c /Fobuild\temp.win32-3.8\Release\MySQLdb/_mysql.obj
      _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\\2017\\Community\\VC\\Tools\\MSVC\\14.14.26428\\bin\\HostX86\\x86\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mysqlclient
  error: subprocess-exited-with-error

  × Running setup.py install for mysqlclient did not run successfully.
  │ exit code: 1
  ╰─> [33 lines of output]
      running install
      C:\Users\Pua Hoover\.virtualenvs\storefront-yT6GZW6h\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn[
      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
      warning: build_py: byte-compiling is disabled, skipping.

      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\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -Dversion_info=[2,1,0,'final',0] -D__version__=2.1.0 "-IC:\Program Files [x86]\MariaDB\MariaDB Connector C\include\mariadb" "-IC:\Program Files [x86]\MariaDB\MariaDB Connector C\include" "-IC:\Users\Pua Hoover\.virtualenvs\storefront-yT6GZW6h\include" "-Ic:\users\pua hoover\appdata\local\programs\python\python38-32\include" "-Ic:\users\pua hoover\appdata\local\programs\python\python38-32\Include" "-IC:\Program Files [x86]\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include" "-IC:\Program Files [x86]\Windows Kits\10\include\10.0.16299.0\ucrt" "-IC:\Program Files [x86]\Windows Kits\10\include\10.0.16299.0\shared" "-IC:\Program Files [x86]\Windows Kits\10\include\10.0.16299.0\um" "-IC:\Program Files [x86]\Windows Kits\10\include\10.0.16299.0\winrt" "-IC:\Program Files [x86]\Windows Kits\10\include\10.0.16299.0\cppwinrt" /TcMySQLdb/_mysql.c /Fobuild\temp.win32-3.8\Release\MySQLdb/_mysql.obj
      _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\\2017\\Community\\VC\\Tools\\MSVC\\14.14.26428\\bin\\HostX86\\x86\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> mysqlclient

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

Cập nhật. Tôi đã tải xuống bánh xe từ Gói mở rộng Python cho Windows - Christoph Gohlke và cài đặt nó. Có vẻ như tôi đã cài đặt thành công mysqlclient

[storefront-yT6GZW6h] C:\Users\Pua Hoover\Desktop\storefront>pipenv install mysqlclient-1.4.6-cp38-cp38-win32.whl
Installing mysqlclient-1.4.6-cp38-cp38-win32.whl...
Adding mysqlclient to Pipfile's [packages]...
Installation Succeeded
Installing dependencies from Pipfile.lock [8c9880]...
  ================================ 1/1 - 00:00:00
[storefront-yT6GZW6h] C:\Users\Pua Hoover\Desktop\storefront>pip show mysqlclient
Name: mysqlclient
Version: 1.4.6
Summary: Python interface to MySQL
Home-page: //github.com/PyMySQL/mysqlclient-python
Author: Inada Naoki
Author-email: songofacandy@gmail.com
License: GPL
Location: c:\users\pua hoover\.virtualenvs\storefront-yt6gzw6h\lib\site-packages
Requires:
Required-by:

Tuy nhiên, khi tôi thay đổi cơ sở dữ liệu từ sqlite sang mysql trong cài đặt. py và runserver theo hướng dẫn, tôi gặp lỗi bên dưới

Làm cách nào để cài đặt máy khách MySQL cho Python?

Nhập lệnh cho gói bạn muốn cài đặt. .
Để cài đặt gói mysqlclient, gõ lệnh sau. Sao chép pip cài đặt mysqlclient
Để cài đặt gói mysql-connector-python, gõ lệnh sau. Sao chép pip cài đặt mysql-connector-python
Để cài đặt gói pymysql, gõ lệnh sau

Làm cách nào để cài đặt máy khách MySQL trong Windows?

Để cài đặt MySQL Shell trên Microsoft Windows bằng Trình cài đặt MSI, hãy làm như sau. Tải xuống gói Windows [x86, 64-bit], Trình cài đặt MSI từ http. // nhà phát triển. mysql. com/tải xuống/vỏ/. Khi được nhắc, bấm Chạy. Làm theo các bước trong Trình hướng dẫn cài đặt

Làm cách nào để cài đặt máy khách MySQL Django?

Thiết lập Dự án Django .
Bước 1. Cài đặt máy khách MySQL. Bạn có thể cài đặt máy khách MySQL trực tiếp thông qua pip bằng lệnh. pip cài đặt mysqlclient. .
Bước 2. Cập nhật chuỗi kết nối. mở cài đặt. py của dự án Django. .
Bước 3. Thực hiện di chuyển. Bây giờ hãy chạy lệnh

Làm cách nào để cài đặt ứng dụng khách MySQL trong PyCharm?

Làm cách nào để cài đặt MySQL trên PyCharm? .
Mở Tệp > Cài đặt > Dự án từ menu PyCharm. .
Chọn dự án hiện tại của bạn
Nhấp vào tab Trình thông dịch Python trong tab dự án của bạn
Nhấp vào biểu tượng + nhỏ để thêm thư viện mới vào dự án

Chủ Đề