sails.js

Configuring mysql with sails.js

How to configure mysql database connection in sails.js

To do this first locate config folder in your root. Then open connections.js

Locate

  // someMysqlServer: {
  //   adapter: 'sails-mysql',
  //   host: 'YOUR_MYSQL_SERVER_HOSTNAME_OR_IP_ADDRESS',
  //   user: 'YOUR_MYSQL_USER', //optional
  //   password: 'YOUR_MYSQL_PASSWORD', //optional
  //   database: 'YOUR_MYSQL_DB' //optional
  // },

Uncomment these lines.

Give suitable name for the connector like this someMysqlServer to mysql_connection or any name as your wish

  mysql_connection: {
    adapter: 'sails-mysql',
    host: '127.0.0.1', // can user localhost or mysql connection either
    user: 'root', // your mysql username
    password: 'xxxxxxxxx', // your mysql password
    database: 'your database name here' // database name
  },

Save file

Go to your root folder and run following command :

$ npm install sails-mysql --save

Note: by running above command we are installing mysql driver package for sails.js.

Your are done.

Now you can use mysql_connection as connection name in your model config. When you lift your app using following command:

$ sails lift

you model schema will automatically get updated in MySQL database


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow