You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Sails.JS 1.0.0无法连接NAS上MariaDB的问题求助

Troubleshooting Sails.js Connection to NAS-hosted MariaDB

Hey there! Let's work through why your Sails.js test app can't connect to the MariaDB running on your NAS. I've broken down common issues and fixes below:

1. Verify Network Connectivity First

First, make sure your Sails server can actually reach the NAS:

  • Ping the NAS IP to confirm basic connectivity:
    ping 192.168.178.11
    
  • Test if the MariaDB port (3306) is open and accessible:
    nc -zv 192.168.178.11 3306
    

If either of these fail, check your NAS firewall settings—most NAS devices block external access to database ports by default. You'll need to allow inbound traffic on port 3306 from your Sails server's IP.

2. Confirm MariaDB User Permissions

It’s common for database users to be restricted to localhost only. Let’s check and fix that:

  • Log into your MariaDB instance (directly on the NAS or via a tool like phpMyAdmin) and run:
    SELECT host, user FROM mysql.user WHERE user='asd';
    
  • If the host column shows localhost or 127.0.0.1, your user can’t connect from your Sails server. Update it with:
    -- Allow connection from any IP (use your Sails server's specific IP instead of % for better security)
    GRANT ALL PRIVILEGES ON asd.* TO 'asd'@'%' IDENTIFIED BY 'asd';
    FLUSH PRIVILEGES;
    

3. Check if the Target Database Exists

Double-check that the asd database actually exists on your MariaDB server:

SHOW DATABASES;

If it’s missing, create it with CREATE DATABASE asd;

4. Fix Incomplete Model Configuration

Your config/models.js has a truncated migrate value—finish that first, as incomplete config can cause unexpected behavior:

module.exports.models = {
  migrate: 'safe', // Or 'alter'/'drop' depending on your needs
  // Other model settings...
};

5. Ensure the MySQL Adapter is Installed

Make sure you’ve installed the sails-mysql adapter for your project:

  • Check if it’s listed in your package.json:
    npm list sails-mysql
    
  • If not, install it:
    npm install sails-mysql --save
    

6. Inspect Detailed Error Logs

Run sails lift in your terminal and look for the full error message. It will tell you exactly what’s wrong:

  • ER_ACCESS_DENIED_ERROR: Authentication failed (check username/password or permissions)
  • ETIMEDOUT: Network connection timed out (firewall/port issue)
  • ER_BAD_DB_ERROR: The specified database doesn’t exist

Share the exact error message if you’re still stuck—it’ll help narrow things down faster!

内容的提问来源于stack exchange,提问作者Shelltux

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:23:30