Skip to content

Instantly share code, notes, and snippets.

View davidromani's full-sized avatar

David Romaní davidromani

View GitHub Profile
@davidromani
davidromani / CSV to MySQL
Created May 8, 2012 06:12
Import CSV into MySQL table
LOAD DATA LOCAL INFILE '/path/to/file.csv' INTO TABLE <database.table_name>
FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
(field1, field2, fieldN);
@davidromani
davidromani / Backup and Restore MySQL databases
Last active October 19, 2016 14:12
Backup and Restore MySQL database
### MySQL v5.0
mysqldump -h <host> -u <username> -p <password> <database_name> > backup_db_file.sql
mysql -u <username> -p <password> <database_name> < <backup_db_file.sql>
### MySQL v5.5
mysqldump -h <host> -u <username> -p <database_name> > backup_db_file.sql
mysql --user=<username> --password=<pass> -A <database_name> < <backup_db_file.sql>
### MySQL ROOT migrations with secure copy remote
mysqldump -u root -p<pass> -B --opt --events --routines --triggers <database_name> | ssh <user>@<remote_host> 'cat - | mysql -u root -p<pass>'
CREATE DATABASE `<dbname>` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER <user> IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON <dbname>.* TO <user>@localhost;
FLUSH PRIVILEGES;
@davidromani
davidromani / Export MySQL table into CSV
Last active October 19, 2016 14:14
Export MySQL table into CSV
SELECT * INTO OUTFILE 'result.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM <table>;
@davidromani
davidromani / Get used space amount of directories
Last active August 29, 2015 13:56
Get UNIX directory space
# Get used space amount of directories (-d 1 = recursivity depth)
du -c -h -d 1 /path/to/your/dir
@davidromani
davidromani / get MySQL databases size
Last active August 29, 2015 13:57
Get MySQL databases size
SELECT table_schema, sum(data_length + index_length)/1024/1024 AS used_space_mb FROM information_schema.TABLES GROUP BY table_schema;
@davidromani
davidromani / dbreset.sh
Created September 25, 2016 09:12
Symfony DB reset bash script helper
#!/bin/bash
if [ -z "$1" ]
then
php app/console doctrine:database:drop --force
php app/console doctrine:database:create
php app/console doctrine:schema:update --force
# php app/console doctrine:migrations:diff
# php app/console doctrine:migrations:mig
php app/console hautelook_alice:doctrine:fixtures:load -n
@davidromani
davidromani / test.sh
Last active September 25, 2016 09:14
Symfony test bash script helper
#!/bin/bash
echo "Started at `date +"%T %d/%m/%Y"`"
if [ -z "$1" ]
then
phpunit -c app/
else
if [ "$1" = "cc" -o "$1" = "coverage" ]
then
@davidromani
davidromani / pre-commit.sh
Created January 23, 2017 11:00
Apply PHP CS fixer Symfony rules in Githook pre-commit
#!/bin/bash
if [ -x "$(command -v php-cs-fixer)" ]; then
FILES=`git diff --name-only`
printf '%s\n' "$FILES" | while IFS= read -r FILE
do
if [[ $FILE == "src/"* ]]; then
php-cs-fixer fix "$FILE" --rules=@Symfony
# git add "$FILE"
fi
@davidromani
davidromani / .bash_profile
Last active December 3, 2019 17:23
Bash aliases
# bash console
alias cl="clear"
alias lsl="ls -lh"
alias lsla="ls -lha"
alias sz="du -c -h -d 1"
# symfony
alias sf="sf2"
alias sf2="php app/console"
alias sf3="php bin/console"