prepare docker mysql

docker run -p 3305:3306 --name mysql56 -v D:\docker_data\mysql:/var/lib/mysql -v D:\docker_data\mysql\conf:/etc/mysql/conf.d -v D:\docker_data\mysql\log:/var/log/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6

install mysql

npm install mysql

implementation

require('magic-globals')
var log4js = require("./log4js");
var log = log4js.getLogger("mysql_helper.js");
var mysql = require('mysql');
var pool = mysql.createPool({
    host: 'localhost',
    user: 'root',
    password: '123456',
    port: '3305',
    database: 'file_worker'
});

pool.getConnection(function (err, connection) {
    // Use the connection
    connection.query("SELECT * FROM mail_process_log WHERE request_no = ? ", [request_no], function (err, rows) {
        // And done with the connection.
        connection.release();
        if (err) {
            console.log("Error Query : %s ", err);
            log.error("[" + __line + "] " + err)
            callback(err, null);
        }
        else {
            console.log("Query : " + rows.length + " ok");
            log.debug("[" + __line + "] " + "Query : " + rows.length + " ok");
            callback(null, JSON.stringify(rows));
        }
        // Don't use the connection here, it has been returned to the pool.
    });
});

github mysql

https://github.com/mysqljs/mysql

Node.js, MySQL & Express: Simple Add, Edit, Delete, View (CRUD)

http://blog.chapagain.com.np/node-js-express-mysql-simple-add-edit-delete-view-crud/

mysql-docker.sh

# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql

# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE

MySQL 超新手入門

http://www.codedata.com.tw/database/mysql-tutorial-8-storage-engine-datatype/

results matching ""

    No results matching ""