xiaoluoge11 / lmanager

190 stars 176 forks source link

初始化数据失败 #1

Open cloudbps opened 8 years ago

cloudbps commented 8 years ago

问题:

cat config.ini 
[db]
db_host = localhost 
db_port = 3306
db_user = cmdb
db_pass = redhat
db_name = cmdb

异常日志:

 ./manage.py  syncdb
Syncing...
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib64/python2.6/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/lib64/python2.6/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib64/python2.6/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib64/python2.6/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/usr/lib64/python2.6/site-packages/django/core/management/base.py", line 415, in handle
    return self.handle_noargs(**options)
  File "/usr/lib/python2.6/site-packages/south/management/commands/syncdb.py", line 89, in handle_noargs
    db.connection_init() 
  File "/usr/lib/python2.6/site-packages/south/db/mysql.py", line 183, in connection_init
    cursor = self._get_connection().cursor()
  File "/usr/lib64/python2.6/site-packages/django/db/backends/__init__.py", line 160, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/usr/lib64/python2.6/site-packages/django/db/backends/__init__.py", line 132, in _cursor
    self.ensure_connection()
  File "/usr/lib64/python2.6/site-packages/django/db/backends/__init__.py", line 127, in ensure_connection
    self.connect()
  File "/usr/lib64/python2.6/site-packages/django/db/utils.py", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/lib64/python2.6/site-packages/django/db/backends/__init__.py", line 127, in ensure_connection
    self.connect()
  File "/usr/lib64/python2.6/site-packages/django/db/backends/__init__.py", line 115, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/lib64/python2.6/site-packages/django/db/backends/mysql/base.py", line 435, in get_new_connection
    conn = Database.connect(**conn_params)
  File "/usr/lib64/python2.6/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib64/python2.6/site-packages/MySQLdb/connections.py", line 193, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")
cloudbps commented 8 years ago

已经在config.ini中指定了cmdb这个用户,但是在初始化数据的时候还是用root这个用户去链接.

xiaoluoge11 commented 8 years ago

首先要确认安装了MySQLdb,木块,然后python-devel ,然后在config.ini里面的数据库配置上面配置好自己的相对名称,看样子应该是用户名或者密码没有授权。检查一下这个用户名和密码能否登录

在 2015-09-23 11:08:30,"Xin Liu" notifications@github.com 写道:

问题: 通过manage.py初始化数据失败,下面是异常日志 已经在mysql中授权本用户对cmdb数据库的所有访问权限 backend/config.ini cat config.ini [db] db_host = localhost db_port = 3306 db_user = cmdb db_pass = redhat db_name = cmdb 异常日志: ./manage.py syncdb Syncing... Traceback (most recent call last): File "./manage.py", line 10, in execute_from_command_line(sys.argv) File "/usr/lib64/python2.6/site-packages/django/core/management/init.py", line 399, in execute_from_command_line utility.execute() File "/usr/lib64/python2.6/site-packages/django/core/management/init.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib64/python2.6/site-packages/django/core/management/base.py", line 242, in run_from_argv self.execute(args, options.dict) File "/usr/lib64/python2.6/site-packages/django/core/management/base.py", line 285, in execute output = self.handle(args, options) File "/usr/lib64/python2.6/site-packages/django/core/management/base.py", line 415, in handle return self.handle_noargs(options) File "/usr/lib/python2.6/site-packages/south/management/commands/syncdb.py", line 89, in handle_noargs db.connection_init() File "/usr/lib/python2.6/site-packages/south/db/mysql.py", line 183, in connection_init cursor = self.get_connection().cursor() File "/usr/lib64/python2.6/site-packages/django/db/backends/_init.py", line 160, in cursor cursor = self.make_debug_cursor(self.cursor()) File "/usr/lib64/python2.6/site-packages/django/db/backends/init_.py", line 132, in cursor self.ensure_connection() File "/usr/lib64/python2.6/site-packages/django/db/backends/init_.py", line 127, in ensure_connection self.connect() File "/usr/lib64/python2.6/site-packages/django/db/utils.py", line 99, in exit six.reraise(dj_exc_type, dj_exc_value, traceback) File "/usr/lib64/python2.6/site-packages/django/db/backends/init.py", line 127, in ensure_connection self.connect() File "/usr/lib64/python2.6/site-packages/django/db/backends/init.py", line 115, in connect self.connection = self.get_new_connection(conn_params) File "/usr/lib64/python2.6/site-packages/django/db/backends/mysql/base.py", line 435, in get_new_connection conn = Database.connect(conn_params) File "/usr/lib64/python2.6/site-packages/MySQLdb/init.py", line 81, in Connect return Connection(args, kwargs) File "/usr/lib64/python2.6/site-packages/MySQLdb/connections.py", line 193, in init super(Connection, self).init(args, kwargs2) django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")

— Reply to this email directly or view it on GitHub.

cloudbps commented 8 years ago

授权是没有问题的

 mysql -ucmdb -predhat -hlocalhost
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, 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> 

python-MySQLdb已经安装

python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> 
cloudbps commented 8 years ago

问题已经解决了,在你的CMDB/setings.py中已经写死了配置了,修改下就可以了

cloudbps commented 8 years ago
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'cmdb',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': 'cmdb',
        'PASSWORD': 'redhat',
        'HOST': 'localhost',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '3306',                      # Set to empty string for default.
    }
}

这个地方应该引入config.ini的配置吧

xiaoluoge11 commented 8 years ago

嗯对的,这里我写好了模块,应该不用你自己修改的

At 2015-09-23 11:24:50, "Xin Liu" notifications@github.com wrote:

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.'NAME': 'cmdb', # Or path to database file if using sqlite3.# The following settings are not used with sqlite3:'USER': 'cmdb', 'PASSWORD': 'redhat', 'HOST': 'localhost', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.'PORT': '3306', # Set to empty string for default. } }

这个地方应该引入config.ini的配置吧

— Reply to this email directly or view it on GitHub.

xiaoluoge11 commented 8 years ago

稍等一下,好像我打包错了

At 2015-09-23 11:24:50, "Xin Liu" notifications@github.com wrote:

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.'NAME': 'cmdb', # Or path to database file if using sqlite3.# The following settings are not used with sqlite3:'USER': 'cmdb', 'PASSWORD': 'redhat', 'HOST': 'localhost', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.'PORT': '3306', # Set to empty string for default. } }

这个地方应该引入config.ini的配置吧

— Reply to this email directly or view it on GitHub.

cloudbps commented 8 years ago

恩,默认的话只能用root这个用户,以及密码必须是123456

xiaoluoge11 commented 8 years ago

您好,已经更新代码了,可以再去github上面下载最新版本

At 2015-09-23 11:24:50, "Xin Liu" notifications@github.com wrote:

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.'NAME': 'cmdb', # Or path to database file if using sqlite3.# The following settings are not used with sqlite3:'USER': 'cmdb', 'PASSWORD': 'redhat', 'HOST': 'localhost', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.'PORT': '3306', # Set to empty string for default. } }

这个地方应该引入config.ini的配置吧

— Reply to this email directly or view it on GitHub.

xiaoluoge11 commented 8 years ago

谢谢支持,刚才那个版本应该是封装的时候漏封装了,

At 2015-09-23 11:24:50, "Xin Liu" notifications@github.com wrote:

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.'NAME': 'cmdb', # Or path to database file if using sqlite3.# The following settings are not used with sqlite3:'USER': 'cmdb', 'PASSWORD': 'redhat', 'HOST': 'localhost', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.'PORT': '3306', # Set to empty string for default. } }

这个地方应该引入config.ini的配置吧

— Reply to this email directly or view it on GitHub.

xiaoluoge11 commented 8 years ago

您好上面的问题,已经解决了,麻烦重新拉一下代码,刚刚是版本推送时候出问题了,忘记封装了