usenewdatabase# Creates a databasedb.mycollection.insert({"name":"toni","age":26})# A row must be added before the table can be seen in the databaseshowdbs# Table exists nowdb.mycollection.find().pretty()# Show the table# Mongodb schemenpminstall--savemongoose
# Show collectionsshowcollections
# This is how indexing works in MongoDB:db.users.createIndex({lastname:1})# Multiple indexes created at the same time:db.users.createIndex({firstname:1,lastname:1})# Get the row count of a tabledb.customerdata.count({custId:{$gte:1}})# MongoDB usage with javascript//varconn=newMongo();//vardb=conn.getDB("customerdb");//db.customerdata.insert(data);load("C:/Program Files/MongoDB/Server/4.0/scripts/mapreduce.js")
MySQL remote server setup
# If c libraries can't access the server:# 1. Edit configsudonano/etc/mysql/my.cnf
# 2. Comment out:skip-external-locking
bind-address
# 3. Restart MySQLsudoservicemysqlrestart
MySQLdump
# Backup database:mysqldump-uroot-pmysqlDATABASE_NAME>DATABASE.sql
# Restore database:C:\>mysql-uroot-p
mysql>createdatabasemydb;mysql>usemydb;mysql>sourceDATABASE_NAME.sql;# Backup a table:mysqldump-uroot-pmysqlDATABASE_NAMETABLE_NAME>DATABASE_NAME_TABLE_NAME.sql
# Restore a table:mysql-uroot-pmysqlDATABASE_NAME<DATABASE_NAME_TABLE_NAME.sql
MySQL notes
## Change user password:# 1. Login to mysql as root:mysql-uroot-p
# 2. use mysql;# 3. Change password in versions < 5.7.5SETPASSWORDFOR'user'@'localhost'=PASSWORD('PASSWORD_HERE');# 4. Change passwords in versions > 5.7.5ALTERUSER'user'@'localhost'IDENTIFIEDBY'PASSWORD_HERE';## Create a new user# Show users# Create admin userCREATEUSER'admin'@'localhost'IDENTIFIEDBY'PASSWORD_HERE';# Set privilegesGRANTALLPRIVILEGESON*.*TO'admin'@'localhost';# Reload privilegesFLUSHPRIVILEGES;## Fix error: ER_NOT_SUPPORTED_AUTH_MODE# Login to mysql rootmysql-uroot-p
# Change user password to mysql native passwordALTERUSER'admin'@'localhost'IDENTIFIEDWITHmysql_native_passwordBY'PASSWORD_HERE';
MySQL workbench notes
## If 'mysql' and other internal schemas are missing:Edit->Preferences->SQLEditor->ShowMetadataandInternalSchemas->OK->Hitrefreshinthe'SCHEMAS'view.
## Connect remotely to mysql database.# 1. Create a SSH tunnelPutty->Session->HostName->192.168.1.35
Putty->Connection->Data->Auto-loginusername->pi
Putty->Connection->SSH->Auth->Privatekeyfileforauthentication->PRIVATE_KEY_HERE
Putty->Connection->SSH->Auth->Tunnels->Sourceport:3306Putty->Connection->SSH->Auth->Tunnels->Destination:127.0.0.1:3306->Add
Putty->Sessions->setnameto'Saved sessions'->Save
# 2. Download MySQL Workbench# 3. Create a new connectionDatabase->Manageconnections->New
Hostname:127.0.0.1
Port:3306Username:USER_NAME_HERE
Password:StoreinVault
TestConnection
# 4. Open connectionDatabase->Connecttodatabase->
StoredConnection:STORED_CONNECTION_HERE
ConnectionMethod:Standard(TCP/IP)