Personal portfolio - Mauricio Aznar

Mysql

 

Quick commands

dump database into file

mysqldump -u root -p backend > backend.sql

insert dump into database

 mysql -u root -p inopack < backend.sql

create database

 create database inopack;

drop database

drop database inopack;

list all foreign keys for a table

SELECT
  TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME
FROM
  INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE
  REFERENCED_TABLE_SCHEMA = '<database>' AND
  REFERENCED_TABLE_NAME = '<table>';

List all foreign keys for a column

SELECT 
  TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME
FROM
  INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE
  REFERENCED_TABLE_SCHEMA = '<database>' AND
  REFERENCED_TABLE_NAME = '<table>' AND
  REFERENCED_COLUMN_NAME = '<column>';

Drop column in table

ALTER TABLE table_name
  DROP COLUMN column_name;

run script

source D:/Projects/backend.sql;

MAC (OSx)

installment

Uninstall Mysql or any other mysql isntallations

Uninstall mysql

Brew update

brew update

Brew install

brew install mysql

Start mysql service

brew services start mysql

mysql secure installation

mysql_secure_installation

Brew fix

Brew fix