-2

我对这个 node.js 和 ubuntu 很陌生。现在我正在尝试在我的应用程序中使用 mysql 数据库。因为我有以下代码:

var mysql = require( "db-mysql" );
  new mysql.Database({
    hostname: "localhost",
    user: "dave",
    password: "asdfa",.
    database: "dbNameHere"
  }).on( "error", function( error ) {
    console.log( "ERROR: " + error );
  }).on( "ready", function( server ) {
   console.log( "Connected to " + server.hostname + " (" + server.version + ")" );
  }).connect( function( error ) {

   if ( error ) {
     console.log( "Error on connect: " + error );
   }

   this.query( "SELECT * FROM " + this.name( "USER" ) ).
   execute( function( error, rows, cols ) {

     if ( error ) {
       console.log( "Error on select: " + error );
       return;
     }

     response.writeHead( 200, { "Content-Type": "text/plain" } );
     response.write( JSON.stringify( rows ) );
     response.end();
   });
  });

当我尝试安装 Mysql 时,我执行了以下命令:

sudo apt-get install libmysqlclient-dev.

Npm-debug.log:

0 info it worked if it ends with ok
1 verbose cli [ 'node', '/usr/local/bin/npm', 'install', 'db-mysql' ]
2 info using npm@1.1.37
3 info using node@v0.6.21-pre
4 verbose config file /home/testuser/.npmrc
5 verbose config file /usr/local/etc/npmrc
6 verbose config file /usr/local/lib/node_modules/npm/npmrc
7 verbose read json /home/testuser/package.json
8 verbose read json /home/testuser/node_modules/mysql/package.json
9 verbose read json /home/testuser/node_modules/mysql-libmysqlclient/package.json
10 verbose read json /home/testuser/node_modules/sequelize/package.json
11 verbose read json /home/testuser/package.json
12 verbose cache add [ 'db-mysql', null ]
13 silly cache add name=undefined spec="db-mysql" args=["db-mysql",null]
14 verbose parsed url { pathname: 'db-mysql', path: 'db-mysql', href: 'db-mysql' }
15 silly lockFile c75423d9-db-mysql db-mysql
16 verbose lock db-mysql /home/testuser/.npm/c75423d9-db-mysql.lock
17 silly lockFile c75423d9-db-mysql db-mysql
18 verbose addNamed [ 'db-mysql', '' ]
19 verbose addNamed [ null, '' ]
20 silly lockFile a4731413-db-mysql db-mysql@
21 verbose lock db-mysql@ /home/testuser/.npm/a4731413-db-mysql.lock
22 silly addNameRange { name: 'db-mysql', range: '', hasData: false }
23 verbose url raw db-mysql
24 verbose url resolving [ 'https://registry.npmjs.org/', './db-mysql' ]
25 verbose url resolved https://registry.npmjs.org/db-mysql
26 info retry registry request attempt 1 at 17:51:57
27 verbose etag "E4EEBUJPZJAULNP5XIVFP2JS4"
28 http GET https://registry.npmjs.org/db-mysql
29 http 304 https://registry.npmjs.org/db-mysql
30 silly registry.get cb [ 304,
30 silly registry.get   { server: 'CouchDB/1.3.0 (Erlang OTP/R15B03)',
30 silly registry.get     etag: '"E4EEBUJPZJAULNP5XIVFP2JS4"',
30 silly registry.get     date: 'Mon, 12 Aug 2013 12:21:56 GMT',
30 silly registry.get     'content-length': '0' } ]
31 verbose etag db-mysql from cache
32 silly addNameRange number 2 { name: 'db-mysql', range: '', hasData: true }
33 silly addNameRange versions [ 'db-mysql',
33 silly addNameRange   [ '0.4.0',
33 silly addNameRange     '0.4.1',
33 silly addNameRange     '0.4.2',
33 silly addNameRange     '0.4.3',
33 silly addNameRange     '0.4.4',
33 silly addNameRange     '0.4.5',
33 silly addNameRange     '0.4.6',
33 silly addNameRange     '0.4.7',
33 silly addNameRange     '0.4.8',
33 silly addNameRange     '0.4.9',
33 silly addNameRange     '0.5.0',
33 silly addNameRange     '0.5.1',
33 silly addNameRange     '0.5.2',
33 silly addNameRange     '0.5.3',
33 silly addNameRange     '0.5.4',
33 silly addNameRange     '0.5.5',
33 silly addNameRange     '0.5.6',
33 silly addNameRange     '0.5.7',
33 silly addNameRange     '0.5.8',
33 silly addNameRange     '0.5.9',
33 silly addNameRange     '0.6.0',
33 silly addNameRange     '0.6.1',
33 silly addNameRange     '0.6.2',
33 silly addNameRange     '0.6.3',
33 silly addNameRange     '0.6.4',
33 silly addNameRange     '0.6.5',
33 silly addNameRange     '0.6.6',
33 silly addNameRange     '0.6.7',
33 silly addNameRange     '0.6.8',
33 silly addNameRange     '0.6.9',
33 silly addNameRange     '0.7.0',
33 silly addNameRange     '0.7.1',
33 silly addNameRange     '0.7.2',
33 silly addNameRange     '0.7.3',
33 silly addNameRange     '0.7.4',
33 silly addNameRange     '0.7.5',
33 silly addNameRange     '0.7.6' ] ]
34 verbose addNamed [ 'db-mysql', '0.7.6' ]
35 verbose addNamed [ '0.7.6', '0.7.6' ]
36 silly lockFile f70b617c-db-mysql-0-7-6 db-mysql@0.7.6
37 verbose lock db-mysql@0.7.6 /home/testuser/.npm/f70b617c-db-mysql-0-7-6.lock
38 verbose read json /home/testuser/.npm/db-mysql/0.7.6/package/package.json
39 silly lockFile f70b617c-db-mysql-0-7-6 db-mysql@0.7.6
40 silly lockFile a4731413-db-mysql db-mysql@
41 silly resolved [ { name: 'db-mysql',
41 silly resolved     description: 'MySQL database bindings for Node.JS',
41 silly resolved     keywords:
41 silly resolved      [ 'database',
41 silly resolved        'db',
41 silly resolved        'native',
41 silly resolved        'binding',
41 silly resolved        'library',
41 silly resolved        'plugin',
41 silly resolved        'client',
41 silly resolved        'mysql',
41 silly resolved        'libmysql' ],
41 silly resolved     homepage: 'http://nodejsdb.org/db-mysql',
41 silly resolved     version: '0.7.6',
41 silly resolved     engines: { node: '>=0.4.1' },
41 silly resolved     maintainers: [ [Object] ],
41 silly resolved     bugs: { url: 'http://github.com/mariano/node-db-mysql/issues' },
41 silly resolved     licenses: [ [Object] ],
41 silly resolved     repositories: [ [Object] ],
41 silly resolved     main: './db-mysql',
41 silly resolved     scripts:
41 silly resolved      { install: 'node-waf configure build',
41 silly resolved        preuninstall: 'rm -rf build/*',
41 silly resolved        test: 'node-waf test',
41 silly resolved        doc: 'node-waf doc' },
41 silly resolved     devDependencies: { nodeunit: '*', nodelint: '*' },
41 silly resolved     readme: '# db-mysql: MySQL database bindings for Node.js #\n\nFor detailed information about this and other Node.js\ndatabase bindings visit the [Node.js db-mysql homepage] [homepage].\n\n## INSTALL ##\n\nBefore proceeding with installation, you need to have the libmysql\ndevelopment libraries and include files. Access to the mysql_config \nbinary is mandatory, and its path has to be specified prior to \ninstallation (if its not within the system\'s path). For example, if \nthe path to your mysql_config is /usr/local/bin/mysql_config make \nsure to do the following (Ubuntu users need to install the \nlibmysqlclient-dev package):\n\n```bash\n$ export MYSQL_CONFIG=/usr/local/bin/mysql_config\n```\n\nOnce you are sure that either mysql_config is part of the path or that\nyou specified the MYSQL_CONFIG environment var, install with npm:\n\n```bash\n$ npm install db-mysql\n```\n\n## QUICK START ##\n\n```javascript\nvar mysql = require(\'db-mysql\');\nnew mysql.Database({\n    hostname: \'localhost\',\n    user: \'root\',\n    password: \'password\',\n    database: \'node\'\n}).connect(function(error) {\n    if (error) {\n        return console.log("CONNECTION ERROR: " + error);\n    }\n\n    this.query().select(\'*\').from(\'users\').execute(function(error, rows) {\n        if (error) {\n            return console.log(\'ERROR: \' + error);\n        }\n        console.log(rows.length + \' ROWS\');\n    });\n});\n```\n\n## LICENSE ##\n\nThis module is released under the [MIT License] [license].\n\n[homepage]: http://nodejsdb.org/db-mysql\n[license]: http://www.opensource.org/licenses/mit-license.php\n',
41 silly resolved     _id: 'db-mysql@0.7.6',
41 silly resolved     _from: 'db-mysql' } ]
42 info install db-mysql@0.7.6 into /home/testuser
43 info installOne db-mysql@0.7.6
44 verbose from cache /home/testuser/.npm/db-mysql/0.7.6/package/package.json
45 info /home/testuser/node_modules/db-mysql unbuild
46 verbose read json /home/testuser/node_modules/db-mysql/package.json
47 verbose tar unpack /home/testuser/.npm/db-mysql/0.7.6/package.tgz
48 silly lockFile 8eb30dcd-e-testuser-node-modules-db-mysql /home/testuser/node_modules/db-mysql
49 verbose lock /home/testuser/node_modules/db-mysql /home/testuser/.npm/8eb30dcd-e-testuser-node-modules-db-mysql.lock
50 silly gunzTarPerm modes [ '755', '644' ]
51 silly gunzTarPerm extractEntry package.json
52 silly gunzTarPerm extractEntry .npmignore
53 silly gunzTarPerm extractEntry README.md
54 silly gunzTarPerm extractEntry mysql-test-long-number.js
55 silly gunzTarPerm extractEntry tests-db.js
56 silly gunzTarPerm extractEntry mysql-test-insert.js
57 silly gunzTarPerm extractEntry mysql-test-placeholder.js
58 silly gunzTarPerm extractEntry mysql-test-sync.js
59 silly gunzTarPerm extractEntry mysql-test-async.js
60 silly gunzTarPerm extractEntry mysql-test-no-connection.js
61 silly gunzTarPerm extractEntry mysql-test-sync-update.js
62 silly gunzTarPerm extractEntry db-mysql.js
63 silly gunzTarPerm extractEntry tests.js
64 silly gunzTarPerm extractEntry mysql-test-manual-query.js
65 silly gunzTarPerm extractEntry mysql-test.js
66 silly gunzTarPerm extractEntry mysql-test-long.js
67 silly gunzTarPerm extractEntry t.js
68 silly gunzTarPerm extractEntry src/connection.h
69 silly gunzTarPerm extractEntry src/mysql.cc
70 silly gunzTarPerm extractEntry src/mysql_bindings.cc
71 silly gunzTarPerm extractEntry src/mysql.h
72 silly gunzTarPerm extractEntry src/query.h
73 silly gunzTarPerm extractEntry src/result.cc
74 silly gunzTarPerm extractEntry src/query.cc
75 silly gunzTarPerm extractEntry src/result.h
76 silly gunzTarPerm extractEntry src/connection.cc
77 silly gunzTarPerm extractEntry CHANGELOG
78 silly gunzTarPerm extractEntry tests-settings.json
79 silly gunzTarPerm extractEntry lib/node-db/README.md
80 silly gunzTarPerm extractEntry lib/node-db/tests.js
81 silly gunzTarPerm extractEntry lib/node-db/exception.h
82 silly gunzTarPerm extractEntry lib/node-db/node_defs.h
83 silly gunzTarPerm extractEntry lib/node-db/binding.cc
84 silly gunzTarPerm extractEntry lib/node-db/events.h
85 silly gunzTarPerm extractEntry lib/node-db/events.cc
86 silly gunzTarPerm extractEntry lib/node-db/connection.h
87 silly gunzTarPerm extractEntry lib/node-db/exception.cc
88 silly gunzTarPerm extractEntry lib/node-db/query.h
89 silly gunzTarPerm extractEntry lib/node-db/result.cc
90 silly gunzTarPerm extractEntry lib/node-db/query.cc
91 silly gunzTarPerm extractEntry lib/node-db/result.h
92 silly gunzTarPerm extractEntry lib/node-db/binding.h
93 silly gunzTarPerm extractEntry lib/node-db/connection.cc
94 silly gunzTarPerm extractEntry doc/api.html
95 silly gunzTarPerm extractEntry doc/changelog.html
96 silly gunzTarPerm extractEntry doc/index.html
97 silly gunzTarPerm extractEntry .gitmodules
98 silly gunzTarPerm extractEntry wscript
99 verbose read json /home/testuser/node_modules/db-mysql/package.json
100 silly lockFile 8eb30dcd-e-testuser-node-modules-db-mysql /home/testuser/node_modules/db-mysql
101 info preinstall db-mysql@0.7.6
102 verbose from cache /home/testuser/node_modules/db-mysql/package.json
103 verbose readDependencies using package.json deps
104 verbose from cache /home/testuser/node_modules/db-mysql/package.json
105 verbose readDependencies using package.json deps
106 silly resolved []
107 verbose about to build /home/testuser/node_modules/db-mysql
108 info build /home/testuser/node_modules/db-mysql
109 verbose from cache /home/testuser/node_modules/db-mysql/package.json
110 verbose linkStuff [ false, false, false, '/home/testuser/node_modules' ]
111 info linkStuff db-mysql@0.7.6
112 verbose linkBins db-mysql@0.7.6
113 verbose linkMans db-mysql@0.7.6
114 verbose rebuildBundles db-mysql@0.7.6
115 info install db-mysql@0.7.6
116 verbose unsafe-perm in lifecycle true
117 silly exec sh "-c" "node-waf configure build"
118 silly sh,-c,node-waf configure build,/home/testuser/node_modules/db-mysql spawning
119 info db-mysql@0.7.6 Failed to exec install script
120 info /home/testuser/node_modules/db-mysql unbuild
121 verbose from cache /home/testuser/node_modules/db-mysql/package.json
122 info preuninstall db-mysql@0.7.6
123 verbose unsafe-perm in lifecycle true
124 silly exec sh "-c" "rm -rf build/*"
125 silly sh,-c,rm -rf build/*,/home/testuser/node_modules/db-mysql spawning
126 info uninstall db-mysql@0.7.6
127 verbose true,/home/testuser/node_modules,/home/testuser/node_modules unbuild db-mysql@0.7.6
128 info postuninstall db-mysql@0.7.6
129 error db-mysql@0.7.6 install: `node-waf configure build`
129 error `sh "-c" "node-waf configure build"` failed with 1
130 error Failed at the db-mysql@0.7.6 install script.
130 error This is most likely a problem with the db-mysql package,
130 error not with npm itself.
130 error Tell the author that this fails on your system:
130 error     node-waf configure build
130 error You can get their info via:
130 error     npm owner ls db-mysql
130 error There is likely additional logging output above.
131 error System Linux 3.5.0-27-generic
132 error command "node" "/usr/local/bin/npm" "install" "db-mysql"
133 error cwd /home/testuser
134 error node -v v0.6.21-pre
135 error npm -v 1.1.37
136 error code ELIFECYCLE
137 error message db-mysql@0.7.6 install: `node-waf configure build`
137 error message `sh "-c" "node-waf configure build"` failed with 1
138 verbose exit [ 1, true ]

在此之后,我无法在我的系统中找到“Mysql”文件夹。所以请指导我解决这个问题..在此之后我必须做什么。提前致谢。

4

1 回答 1

0

你安装了mysql-server库吗?

sudo apt-get install mysql-server

安装最新版本的nodeJS

// uninstall older nodejs ubuntu install
sudo apt-get autoremove node* npm
// install nodejs latest version
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

使用命令后,nodejs -v您可以看到版本0.10.X

于 2013-08-12T11:59:32.357 回答