Skip to content

Instantly share code, notes, and snippets.

@mschmulen
Last active February 13, 2018 13:33
Show Gist options
  • Save mschmulen/8248247 to your computer and use it in GitHub Desktop.
Save mschmulen/8248247 to your computer and use it in GitHub Desktop.
StrongLoop Datastores git clone https://gist.github.com/8248247.git StrongLoop-DataStores

MariaDB

##Install, Run & Configure mariaDB ( MySQL compliant )

Installing MariaDB OSX

  1. Install with brew brew update then ````brew install mariadb```
  1. sudo apt-get install software-properties-common
  2. sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
  3. sudo add-apt-repository 'deb http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/5.5/ubuntu raring main'
  4. sudo apt-get update
  5. sudo apt-get install mariadb-server

Starting MariaDB

  1. Start MariaDB mysql.server start
  2. Verify by loggin in with mysql -uroot
  3. Log out of the command line with exit

###Creating a DB

  1. Loginto MariaDB mysql -u root -p
  2. Create a database with the following commands CREATE DATABASE IF NOT EXISTS my_database;
  3. Verify the database was created SHOW DATABASES;
  4. Select your database USE my_database;
  5. Create a Table
CREATE TABLE IF NOT EXISTS product (
    product_id int(5) NOT NULL AUTO_INCREMENT,
    name varchar(255) DEFAULT NULL,
	price float(5,2) DEFAULT NULL,
	inventory int(11) DEFAULT NULL,
    PRIMARY KEY(product_id)
    );
  1. Verify the table was created show columns in product;
  2. Insert some data into the DB
INSERT INTO product (name, price, inventory ) VALUES ("Product AA", 22.33, 13);
INSERT INTO product (name, price, inventory ) VALUES ("Product BB", 2.33, 223);
INSERT INTO product (name, price, inventory ) VALUES ("Product CC", 44.33, 993);
  1. Verify the table has data SELECT * FROM product;

##Connect StrongLoop LoopBack to MariaDB

  1. Create a LoopBack project that connects to mariadb using the mySQL connector
slc lb project loopback-mysql
cd loopback-mysql
npm install loopback-connector-mysql --save
slc lb model customer
slc lb model product
slc lb model location
slc lb datasource db --connector mysql

#####Notes

homebrew quick install ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

Set up databases with: unset TMPDIR and mysql_install_db --user=`whoami` --basedir="$(brew --prefix mariadb)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

cd /usr/local/Cellar/mariadb/5.2.6 ; /usr/local/Cellar/mariadb/5.2.6/bin/mysqld_safe --datadir=/usr/local/var/mysql

Start the mariadb daemon

  • Start the mariadb server mysqld_safe --datadir=/usr/local/var/mysql
  • Start the mariadb binded to an ipAddress mysqld_safe --datadir=/usr/local/var/mysql --bind-address=127.0.0.1&

Set a new password with:

/usr/local/opt/mariadb/bin/mysqladmin -u root password 'new-password'
==> Installing mariadb dependency: cmake
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/cmake-2.8.1
######################################################################## 100.0%
==> Pouring cmake-2.8.12.1.mavericks.bottle.1.tar.gz
🍺  /usr/local/Cellar/cmake/2.8.12.1: 701 files, 36M
==> Installing mariadb
==> Downloading http://ftp.osuosl.org/pub/mariadb/mariadb-5.5.34/kvm-tarbake-jau
######################################################################## 100.0%
==> cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/mariadb/5.5.34 -DCMAKE_FIND
==> make
==> make install
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
    mysql -uroot

To have launchd start mariadb at login:
    ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents
Then to load mariadb now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
Or, if you don't want/need launchctl, you can just run:
    mysql.server start
==> /usr/local/Cellar/mariadb/5.5.34/bin/mysql_install_db --verbose --user=matt
==> Summary
🍺  /usr/local/Cellar/mariadb/5.5.34: 483 files, 111M, built in 16.2 minutes

If you want the server to boot when you login to the computer issue the following command. ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents

mysql -u root -p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment