MySQL with Node.js

后端 未结 9 718
Happy的楠姐
Happy的楠姐 2020-11-22 11:52

I\'ve just started getting into Node.js. I come from a PHP background, so I\'m fairly used to using MySQL for all my database needs.

How can I use MySQL with Node.js

9条回答
  •  一生所求
    2020-11-22 12:22

    Since this is an old thread just adding an update:

    To install the MySQL node.js driver:

    If you run just npm install mysql, you need to be in the same directory that your run your server. I would advise to do it as in one of the following examples:

    For global installation:

    npm install -g mysql
    

    For local installation:

    1- Add it to your package.json in the dependencies:

    "dependencies": {
        "mysql": "~2.3.2",
         ...
    

    2- run npm install


    Note that for connections to happen you will also need to be running the mysql server (which is node independent)

    To install MySQL server:

    There are a bunch of tutorials out there that explain this, and it is a bit dependent on operative system. Just go to google and search for how to install mysql server [Ubuntu|MacOSX|Windows]. But in a sentence: you have to go to http://www.mysql.com/downloads/ and install it.

提交回复
热议问题