Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

初始化数据失败 #1

Open
cloudbps opened this issue Sep 23, 2015 · 11 comments
Open

初始化数据失败 #1

cloudbps opened this issue Sep 23, 2015 · 11 comments

Comments

@cloudbps
Copy link

问题:

  • 通过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 <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
Copy link
Author

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

@xiaoluoge11
Copy link
Owner

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

在 2015-09-23 11:08:30,"Xin Liu" [email protected] 写道:

问题:
通过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
Copy link
Author

授权是没有问题的

 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
Copy link
Author

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

@cloudbps
Copy link
Author

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
Copy link
Owner

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

At 2015-09-23 11:24:50, "Xin Liu" [email protected] 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
Copy link
Owner

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

At 2015-09-23 11:24:50, "Xin Liu" [email protected] 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
Copy link
Author

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

@xiaoluoge11
Copy link
Owner

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

At 2015-09-23 11:24:50, "Xin Liu" [email protected] 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
Copy link
Owner

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

At 2015-09-23 11:24:50, "Xin Liu" [email protected] 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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants