简体   繁体   English

python:CommandError:您似乎没有安装“mysql”程序或在您的路径上

[英]python: CommandError: You appear not to have the 'mysql' program installed or on your path

I am working on a Mysql database for a Django app, so I created a database named maison, configure settings.py as bellow:我正在为 Django 应用程序开发 Mysql 数据库,因此我创建了一个名为 maison 的数据库,将 settings.py 配置如下:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'maison',
    'USER': 'root',
    'PASSWORD': '1234',
    'HOST': '127.0.0.1',
    'PORT': '5432',

}
}

And to verify if my database is connected to my app I run the command python manage.py dbshell But it throws that error :并验证我的数据库是否已连接到我的应用程序,我运行命令python manage.py dbshell但它抛出该错误:

CommandError: You appear not to have the 'mysql' program installed or on your path. CommandError:您似乎没有安装“mysql”程序或在您的路径上。

though I have installed all the requirement:虽然我已经安装了所有要求:

  • Python: 3.6蟒蛇:3.6
  • Django: 1.11姜戈:1.11
  • MySQL: 5.7 MySQL:5.7
  • mysqlclient mysql客户端

Do you have any idea to fixe that error??你有什么想法来解决这个错误吗?

In accordance with the code, Django simply runs console app mysql .按照代码,Django 只是运行控制台应用程序mysql Try to call it from console without Django.尝试在没有 Django 的情况下从控制台调用它。 Maybe it not installed, not in PATH enviroment variable or not yet in PATH enviroment variable (try to rehash command or console relogin if you have rehash command).也许它没有安装,不在 PATH 环境变量中或尚未在 PATH 环境变量中(如果有rehash命令,请尝试重新哈希命令或控制台重新登录)。

class DatabaseClient(BaseDatabaseClient):
executable_name = 'mysql'

@classmethod
def settings_to_cmd_args(cls, settings_dict):
    args = [cls.executable_name]
    db = settings_dict['OPTIONS'].get('db', settings_dict['NAME'])
    user = settings_dict['OPTIONS'].get('user', settings_dict['USER'])
    passwd = settings_dict['OPTIONS'].get('passwd', settings_dict['PASSWORD'])
    host = settings_dict['OPTIONS'].get('host', settings_dict['HOST'])
    port = settings_dict['OPTIONS'].get('port', settings_dict['PORT'])
    cert = settings_dict['OPTIONS'].get('ssl', {}).get('ca')
    defaults_file = settings_dict['OPTIONS'].get('read_default_file')
    # Seems to be no good way to set sql_mode with CLI.

    if defaults_file:
        args += ["--defaults-file=%s" % defaults_file]
    if user:
        args += ["--user=%s" % user]
    if passwd:
        args += ["--password=%s" % passwd]
    if host:
        if '/' in host:
            args += ["--socket=%s" % host]
        else:
            args += ["--host=%s" % host]
    if port:
        args += ["--port=%s" % port]
    if cert:
        args += ["--ssl-ca=%s" % cert]
    if db:
        args += [db]
    return args

def runshell(self):
    args = DatabaseClient.settings_to_cmd_args(self.connection.settings_dict)
    subprocess.check_call(args)

mysql-client path may not be added in your machine. mysql-client 路径可能未添加到您的机器中。

for linux please execute the below command line:对于 linux 请执行以下命令行:

echo 'export PATH=/usr/local/opt/mysql-client/bin:$PATH' >> ~/.bash_profile echo 'export PATH=/usr/local/opt/mysql-client/bin:$PATH' >> ~/.bash_profile

If it is a windows system please add the mysql-client path in the environment.如果是windows系统请在环境中添加mysql-client路径。

尝试运行python manage.py shell ,它对我python manage.py shell ,我认为它也对你有用!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CommandError:您似乎没有安装“psql”程序或在您的路径上 - CommandError: You appear not to have the 'psql' program installed or on your path CommandError:您似乎没有安装“sqlite3”程序或在您的路径上 - CommandError: You appear not to have the 'sqlite3' program installed or on your path django-admin dbshel​​l CommandError:您似乎没有安装“ sqlite3”程序或在路径上 - django-admin dbshell CommandError: You appear not to have the 'sqlite3' program installed or on your path 1064,“你的SQL语法有错误; ......”Python MySQL - 1064, “You have an error in your SQL syntax;…” Python MySQL Python MySQL, 1064 (42000), “您的 SQL 语法有错误;...” - Python MySQL, 1064 (42000), "You have an error in your SQL syntax;..." 您的 SQL 语法有错误; 检查与您的 MySQL 服务器 PYTHON 相对应的手册 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server PYTHON Python,MySQL _mysql_exceptions.ProgrammingError:(1064,'您的SQL语法有错误 - Python, MySQL _mysql_exceptions.ProgrammingError: (1064, 'You have an error in your SQL syntax 如何在 Python 中获取 Windows 中已安装程序的路径 - How to get in Python the path to a installed program in windows 您的 SQL 语法有错误; 带 python - You have an error in your SQL syntax; With python 如何使用 python 将变量插入 mysql 数据库? “您的 SQL 语法有错误” - How to insert variable to mysql database with python? “You have an error in your SQL syntax”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM