2017年3月23日 星期四

[Node.js][mysql] How to install mysql(mariaDB)

Install mysql(mariaDB) package
sudo pacman -S mysql


Add one new user was called “mysql”.
sudo useradd mysql


Change mysql’s owner
sudo chown mysql:mysql /var/lib/mysql/ -Rf

You need to initialize the MariaDB data directory prior to starting the service.
sudo mysql_install_db –user=mysql –basedir=/usr –datadir=/var/lib/mysql


Mysql(mariaDB) will create mysqld.sock under “/var/run/mysqld”, so I need to prepare right folder and right permission of folder for mysql(mariaDB).
sudo mkdir /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld/


Start mysql(mariaDB) now
sudo systemctl start mysqld


Start mysql(mariaDB) after booting.
sudo systemctl start mysqld


[Node.js][Simple Example] How to connect to mysql

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'localhost',
  user     : '< MySQL username >',
  password : '< MySQL password >',
  database : '<your database name>'
});

connection.connect();

connection.query('SELECT * from < table name >', function(err, rows, fields) {
  if (!err)
    console.log('The solution is: ', rows);
  else
    console.log('Error while performing Query.');
});

connection.end();

Reference:

Related Posts:

  • [java] (4) correct Big5 can display on list mysql SET NAMES 'big5'; \\ Use this first /** To change this template, choose Tools | Templates* and open the template in the editor.*//** test2… Read More
  • [mysql] Jtext 判斷有無輸入 字串 String Price_text = Price_jTextField1.getText(); if ( Price_text.length() == 0 || Price_text == null ){ Price_text = Integer.toString(0); }R… Read More
  • [mysql] latin change to Big5Usually it isnecessary to change only the client and connection andresults settings. There is a simple statement which changesall three at once: SET N… Read More
  • [mysql] commandReference : http://www.pantz.org/software/mysql/mysqlcommands.html Good website : http://idd.ccnet.com.tw/ebook/SOL.htm To login (from unix shell) use… Read More
  • [mysql] Statusmysql status;--------------mysql Ver 14.14 Distrib 5.1.54, for debian-linux-gnu (x86_64) using readline 6.2Connection id: 37Current database: … Read More

0 意見:

張貼留言