django连接mysql指定用户_python-Django中连接MySQL数据库及设置用户名密码

项目和应用创建好以后,进入当前的目录所在的文件夹即可操作,也可以用pycharm中的Tools工具运行manage.py,本人采用的是运行pycharm下的manage.py文件

配置:

1.把对应的应用添加到INSTALLED_APPS下,注意分号

INSTALLED_APPS = [

'django.contrib.admin',

'django.contrib.auth',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.messages',

'django.contrib.staticfiles',

'blog', #应用

]

2.修改数据库连接

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.mysql', # 提示连接mysql数据库

'NAME': 'test', # 数据库名为test,要自己创建

'USER': 'root', # 用户名

'PASSWORD': 'root',    # 密码

'HOST': '127.0.0.1', # 连接的主机

'PORT': '3306', # 对应的端口号

}

}

3.运行:

manage.py@hello_mysite > migrate # 连接数据库

"D:\pycharm\PyCharm 5.0.3\bin\runnerw.exe" D:\python\python.exe "D:\pycharm\PyCharm 5.0.3\helpers\pycharm\django_manage.py" migrate G:/hello_mysite

Operations to perform:

Apply all migrations: admin, auth, contenttypes, sessions

Running migrations:

Applying contenttypes.0001_initial... OK

Applying auth.0001_initial... OK

Applying admin.0001_initial... OK

Applying admin.0002_logentry_remove_auto_add... OK

Applying contenttypes.0002_remove_content_type_name... OK

Applying auth.0002_alter_permission_name_max_length... OK

Applying auth.0003_alter_user_email_max_length... OK

Applying auth.0004_alter_user_username_opts... OK

Applying auth.0005_alter_user_last_login_null... OK

Applying auth.0006_require_contenttypes_0002... OK

Applying auth.0007_alter_validators_add_error_messages... OK

Applying auth.0008_alter_user_username_max_length... OK

Applying sessions.0001_initial... OK

Process finished with exit code 0

manage.py@hello_mysite > makemigrations blog # 关联应用

"D:\pycharm\PyCharm 5.0.3\bin\runnerw.exe" D:\python\python.exe "D:\pycharm\PyCharm 5.0.3\helpers\pycharm\django_manage.py" makemigrations blog G:/hello_mysite

No changes detected in app 'blog'

Process finished with exit code 0

manage.py@hello_mysite > createsuperuser # 创建超级用户

"D:\pycharm\PyCharm 5.0.3\bin\runnerw.exe" D:\python\python.exe "D:\pycharm\PyCharm 5.0.3\helpers\pycharm\django_manage.py" createsuperuser G:/hello_mysite

Username:  root # 用户名

Email address:  root@root.com # 邮箱

Warning: Password input may be echoed.

Password:  root1234 # 密码,不要太短

Warning: Password input may be echoed.

Password (again):  root1234 # 再次输入

Superuser created successfully.

OK了!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值