2013-08-12 29 views
-2

我很新的Node.js和ubuntu.Now我試圖在使用MySQL數據庫我application.For我有以下代碼: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 [email protected] 
3 info using [email protected] 
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 [email protected] 
21 verbose lock [email protected] /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 [email protected] 
37 verbose lock [email protected] /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 [email protected] 
40 silly lockFile a4731413-db-mysql [email protected] 
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: '[email protected]', 
41 silly resolved  _from: 'db-mysql' } ] 
42 info install [email protected] into /home/testuser 
43 info installOne [email protected] 
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 [email protected] 
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 [email protected] 
112 verbose linkBins [email protected] 
113 verbose linkMans [email protected] 
114 verbose rebuildBundles [email protected] 
115 info install [email protected] 
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 [email protected] 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 [email protected] 
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 [email protected] 
127 verbose true,/home/testuser/node_modules,/home/testuser/node_modules unbuild [email protected] 
128 info postuninstall [email protected] 
129 error [email protected] install: `node-waf configure build` 
129 error `sh "-c" "node-waf configure build"` failed with 1 
130 error Failed at the [email protected] 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 [email protected] install: `node-waf configure build` 
137 error message `sh "-c" "node-waf configure build"` failed with 1 
138 verbose exit [ 1, true ] 

這個我不能能夠找到 「mysql的」 折後呃在我的系統中。所以請指導我解決這個問題。之後我必須做些什麼。提前致謝。

+2

您已經安裝了錯誤的東西(開發庫,而不是一個實際的運行)。嘗試使用'apt-get install mysql-server'安裝服務器。您還需要安裝正確的NPM軟件包。基本上,**閱讀教程** – Bojangles

+0

謝謝Bojangles ..我讀了很多的教程,但我不能得到的解決方案..正如我說我對這個概念很新,請指導我.. – Subburaj

+0

你可能會更好只是[使用更流行的庫](https://github.com/felixge/node-mysql)。你編輯的錯誤看起來像'db-mysql'不能構建它的本地擴展 – Bojangles

回答

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

+0

謝謝throrin19..Wheni執行此命令時它說:「mysql-server已經是最新的版本 以下軟件包被自動安裝,需要更長的時間: libido-0.1-0 linux-headers-3.5.0-17 linux-headers-3.5.0-17-generic 使用'apt-get autoremove'去除它們 0升級,0新安裝,0刪除和166未升級。「 – Subburaj

+0

你有沒有啓動mysql服務器? 'sudo服務mysql啓動' – throrin19

+0

它說「啓動:作業已在運行:mysql」 – Subburaj