将Django连接到本地网络上的远程mysql服务器 [英] Connect Django to remote mysql server on a local network

查看:531
本文介绍了将Django连接到本地网络上的远程mysql服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了Django,并且是一个完整的新手。我已经成功地连接到我的本地主机上的一个mysql数据库,但连接到本地网络上另一台机器上托管的数据库时遇到麻烦。



本地主机是:192.168.1.51 (又名笔记本电脑)
远程是:192.168.1.50(又名桌面)



settings.py看起来像这样:

  DATABASES = {
'default':{
'ENGINE':'django.db.backends.mysql',
'NAME':'mydb',
'USER':'root',
'PASSWORD':'mypass',
'HOST':'192.168.1.50',
'PORT':'3306',
}
}

运行'python manage.py runserver'并得到一个错误:


_mysql_exceptions.OperationalError:(1045,访问被拒绝为用户' @'laptop.local'(我们密码:YES))


我已经授权访问root @ laptop,但是我无法弄明白为什么正在添加'.local'....我正在这样做吗?

解决方案

默认情况下,root帐户只能使用在本地登录到mysql。您首先需要从主机授予root用户登录权限。


I have setup Django and am a complete newb. I have successfully connected to a mysql database on my localhost but have had trouble connecting to a database that's hosted on another machine on my local network.

Localhost is: 192.168.1.51 (aka "laptop") Remote is: 192.168.1.50 (aka "desktop")

settings.py looks like this:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': 'mydb',                      
        'USER': 'root',                      
        'PASSWORD': 'mypass',                  
        'HOST': '192.168.1.50',                      
        'PORT': '3306',                      
    }
}

I run 'python manage.py runserver' and get an error:

_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'laptop.local' (using password: YES)")

I've granted access to 'root@laptop' but I can't figure out why it is adding '.local'....Am I doing this right?

解决方案

In default, root account only can be used to login to mysql locally. You need give root user logon permission from the host at first.

这篇关于将Django连接到本地网络上的远程mysql服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆