VPN技术 · 2023年11月10日

使用Node.js创建MySQL表

Node.js MySQL创建表

使用”CREATE TABLE”创建表

首先我们创建一个customers的表

var mysql = require(mysql);var con = mysql.createConnection({   host: "localhost",   user: "yourusername",   password: "yourpassword",   database: "mydb" });con.connect(function(err) {   if (err) throw err;   console.log("Connected!");   var sql = "CREATE TABLE customers (name VARCHAR(255), address VARCHAR(255))";   con.query(sql, function (err, result) {     if (err) throw err;     console.log("Table created");   }); });

保存文件名”demo_create_table.js” 然后再运行

node demo_create_table.js

如果正确会出现

OpenMagic API

Need more than content? Move into the product flow.

If you are here for model access, pricing, developer docs, or the future API console, the dedicated product path now lives on api.openmagic.ai.