简体   繁体   English

如何在Android手机上安装MySQL以与Node.js一起使用

[英]How to install MySQL on Android phone to use with node.js

Are there any MySQL lightweight apps that can be installed on mobile android phone preferably in the background process? 是否有任何MySQL轻量级应用程序可以最好在后台进程中安装在移动android手机上?

I followed this tutorial Building a Node.js application on Android I'm able to run non-SQL node server scripts but I rely on MySQL instances to have a connection on localhost using node.js mysql module. 我遵循了本教程, 在Android上构建Node.js应用程序,我能够运行非SQL节点服务器脚本,但是我依靠MySQL实例使用node.js mysql模块在本地主机上建立连接。

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : 'root',
  database : 'database'
});
connection.connect();

Is there anyway I could create an MySQL instance on android actually? 无论如何,我实际上可以在android上创建MySQL实例吗?

I'd recommend using sqlite3 , because it uses a small file as it's database. 我建议使用sqlite3 ,因为它使用一个小的文件作为数据库。 It has a much smaller footprint than alternatives like mysql and postgres. 它比mysql和postgres等替代方案占用的空间小得多。 Store it in the install directory of the node app and connect to it via a library like knex.js or sqlite3 . 将其存储在节点应用程序的安装目录中,并通过knex.jssqlite3之类的库进行连接。

Example using knex.js (my preference): 使用knex.js的示例(我的偏好):

var knex = require('knex')({
  client: 'sqlite3',
  connection: {
    filename: "./mydb.sqlite"
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM