Last active
February 13, 2018 13:33
-
-
Save mschmulen/8248247 to your computer and use it in GitHub Desktop.
StrongLoop Datastores
git clone https://gist.github.com/8248247.git StrongLoop-DataStores
##Install, Run & Configure mariaDB ( MySQL compliant )
- Install with brew
brew update
then ````brew install mariadb```
Installing MariaDB Ubuntu https://downloads.mariadb.org/mariadb/repositories/
- sudo apt-get install software-properties-common
- sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
- sudo add-apt-repository 'deb http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/5.5/ubuntu raring main'
- sudo apt-get update
- sudo apt-get install mariadb-server
- Start MariaDB
mysql.server start
- Verify by loggin in with
mysql -uroot
- Log out of the command line with
exit
###Creating a DB
- Loginto MariaDB
mysql -u root -p
- Create a database with the following commands
CREATE DATABASE IF NOT EXISTS my_database;
- Verify the database was created
SHOW DATABASES;
- Select your database
USE my_database;
- 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)
);
- Verify the table was created
show columns in product;
- 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);
- Verify the table has data
SELECT * FROM product;
##Connect StrongLoop LoopBack to MariaDB
- 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