django 快速启动数据库客户端程序的方法示例

yipeiwu_com5年前Python基础

实际工作经历中,免不了有时候需要连接数据库进行问题排查分析的场景,之前一直习惯通过 mysql -uxxx -hxxxx -P1234 ... 这样的方式来启动命令行形式的 MySQL 数据库客户端程序,只是用起来比较麻烦,每次都要拷贝各个配置参数,还要记得不要在命令里显式打印密码。后来想起来在开发 Ruby on Rails 程序的时候,其提供了 rails dbconsole 的命令,可以方便直接启动对应的数据库客户端命令行程序,联想到 Django 理论上也有,所以找到了 python manage.py dbshell 这个命令,使用效果和自己手动敲 mysql 命令行是一样的,省去繁琐的参数设定步骤。

使用效果

用法

其用法可以直接查询命令行帮助文档:

# python manage.py dbshell -h
Usage: manage.py dbshell [options]

Runs the command-line client for specified database, or the default database if none is provided.

Options:
 -v VERBOSITY, --verbosity=VERBOSITY
      Verbosity level; 0=minimal output, 1=normal output,
      2=verbose output, 3=very verbose output
 --settings=SETTINGS The Python path to a settings module, e.g.
      "myproject.settings.main". If this isn't provided, the
      DJANGO_SETTINGS_MODULE environment variable will be
      used.
 --pythonpath=PYTHONPATH
      A directory to add to the Python path, e.g.
      "/home/djangoprojects/myproject".
 --traceback   Raise on exception
 --database=DATABASE Nominates a database onto which to open a shell.
      Defaults to the "default" database.
 --version    show program's version number and exit
 -h, --help   show this help message and exit

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

PyQt 线程类 QThread使用详解

PyQt中的线程类 QtCore.QThread ,使用时继承QThread类 启动界面的线程暂称为UI线程。界面执行命令时都在自己的UI线程中。 如果在UI线程中执行网络连接和数据库操...

python字符串str和字节数组相互转化方法

实例如下: # bytes object b = b"example" # str object s = "example" # str to bytes bytes(...

对Python3+gdal 读取tiff格式数据的实例讲解

1、遇到的问题:numpy版本 im_data = dataset.ReadAsArray(0,0,im_width,im_height)#获取数据 这句报错 升级numpy:pip i...

SELENIUM自动化模拟键盘快捷键操作实现解析

SELENIUM自动化模拟键盘快捷键操作实现解析

这篇文章主要介绍了SELENIUM自动化模拟键盘快捷键操作实现解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 平常我们会用到很多快...

Python SQLite3数据库日期与时间常见函数用法分析

本文实例讲述了Python SQLite3数据库日期与时间常见函数。分享给大家供大家参考,具体如下: import sqlite3 #con = sqlite3.connect('e...