Django没有在安装了mysqlclient和数据库工作的CentOS 7上看到我的MySQLdb模块

时间:2018-03-28 01:07:54

标签: python mysql django linux python-3.x

我看过很多帖子都说明了可能出现的问题,但我已经走完了每条路。我有一个数据库服务器,想要创建一个Django网站连接到它。我在服务器上使用mysql5.6,在客户端和服务器上都安装了社区版本 我按照django网站上的说明进行了测试:测试了mysql,测试了安装了django,在python(2.0.3)中测试了它的版本,测试了python版本(3.6),测试了从客户端到服务器的连接与指定用户测试数据库(ok) ,可以在mysql>提示符下选择数据。作为root,已经完成了pip install mysqlclient,已经完成了yum install mysql-community-client等。 我达到了这一点:

  

$ cd / my / site / directory

     

$ python manage.py newserver

>Traceback (most recent call last):
>  File "/usr/lib/python3.6/site-packages/Django-2.0.3 py3.6.egg/django/db/backends/mysql/base.py", line 15, in <module>
>    import MySQLdb as Database
>  File "/usr/lib/python3.6/site-packages/MySQLdb/__init__.py", line 19, in <module>
>import _mysql
>ImportError: dynamic module does not define module export function (PyInit__mysql)

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

>Traceback (most recent call last):
>  File "manage.py", line 15, in <module>
>    execute_from_command_line(sys.argv)
>  File "/usr/lib/python3.6/site-packages/Django-2.0.3-py3.6.egg/django/core/management/__init__.py", line 371, in >execute_from_command_line
    utility.execute()
>  File "/usr/lib/python3.6/site-packages/Django-2.0.3-py3.6.egg/django/core/management/__init__.py", line 347, in execute
    django.setup()
>  File "/usr/lib/python3.6/site-packages/Django-2.0.3-py3.6.egg/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
>  File "/usr/lib/python3.6/site-packages/Django-2.0.3-py3.6.egg/django/apps/registry.py", line 112, in populate
    app_config.import_models()
>  File "/usr/lib/python3.6/site-packages/Django-2.0.3-py3.6.egg/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
>  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
>  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
>  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
>  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
>  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
>  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
>  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
>  File "/usr/lib/python3.6/site-packages/Django-2.0.3-py3.6.egg/django/contrib/auth/models.py", line 2, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
>  File "/usr/lib/python3.6/site-packages/Django-2.0.3-py3.6.egg/django/contrib/auth/base_user.py", line 47, in <module>
    class AbstractBaseUser(models.Model):
>  File "/usr/lib/python3.6/site-packages/Django-2.0.3-py3.6.egg/django/db/models/base.py", line 114, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
>  File "/usr/lib/python3.6/site-packages/Django-2.0.3-py3.6.egg/django/db/models/base.py", line 315, in add_to_class
    value.contribute_to_class(cls, name)
>  File "/usr/lib/python3.6/site-packages/Django-2.0.3-py3.6.egg/django/db/models/options.py", line 205, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
>  File "/usr/lib/python3.6/site-packages/Django-2.0.3-py3.6.egg/django/db/__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
>  File "/usr/lib/python3.6/site-packages/Django-2.0.3-py3.6.egg/django/db/utils.py", line 202, in __getitem__
    backend = load_backend(db['ENGINE'])
>  File "/usr/lib/python3.6/site-packages/Django-2.0.3-py3.6.egg/django/db/utils.py", line 110, in load_backend
    return import_module('%s.base' % backend_name)
>  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
>  File "/usr/lib/python3.6/site-packages/Django-2.0.3-py3.6.egg/django/db/backends/mysql/base.py", line 20, in <module>
    ) from err
>django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
>Did you install mysqlclient?

我即将投降并使用PHP上学,但我真的想使用像Django这样的东西。所有帮助表示赞赏!

这是从客户端(CentOS 7.4)到服务器(也是CentOS 7.4)的MySQL输出:

>Enter password: 
>Reading table information for completion of table and column names
>You can turn off this feature to get a quicker startup with -A>

>Welcome to the MySQL monitor.  Commands end with ; or \g.
>Your MySQL connection id is 25
>Server version: 5.6.39 MySQL Community Server (GPL)

>Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

>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> select * from test;
>+------+----------+
>| fn   | ln       |
>+------+----------+
>| Joe  | DiMaggio |
>+------+----------+
>1 row in set (0.01 sec)

Here is output from django:
>[user@build hdrn]$ python -m django --version
>2.0.3

Here is output from python
$ python
>Python 3.6.4 (default, Mar 27 2018, 14:37:57) 
>[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
>Type "help", "copyright", "credits" or "license" for more information.
>>> 

Here is uname from client machine:
>Linux build.mynetwork.com 3.10.0-693.11.6.el7.x86_64.debug #1 SMP Thu Jan 4 01:24:54 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

--------------结束问题------------------

0 个答案:

没有答案