segunda-feira, 18 de fevereiro de 2019

Creating and updating root password in Mysql


# Creating the first root password

If you have just installed mysql-server and have not set the root password, you will create the password like this:

$ sudo mysqladmin -uroot password 'password' 


# Updating the root password

For updating the root password, you can do like this:

$ sudo mysqladmin -u root -p'oldpassword' password 'newpassword'




sexta-feira, 14 de dezembro de 2018

Regex on VS Code

Place underscore between words

Find: ([A-Za-z])( )([A-Za-z])
Replace: $1_$3

Find

Ano
Sit reg
Dcih
Apres
Espec
Cgc hosp
Org rec
Ident
Org loc
Nome pac
Logr
Numero
Compl
Tipo bairr
Cs
Cs cod

Replace 

Ano
Sit_reg
Dcih
Apres
Espec
Cgc_hosp
Org_rec
Ident
Org_loc
Nome_pac
Logr
Numero
Compl
Tipo_bairr
Cs
Cs_cod








quinta-feira, 22 de novembro de 2018

Importing files from pg_dump


For importing files generated by pg_dump command, use the command pg_restore, like that:

$ pg_restore -Uusername -hlocalhost -c -v -Fc -ddatabase < file.pg_dump

Options:
  • -U: username
  • -h: host
  • -c: drop database before recreating
  • -v: verbose mode
  • -Fc: the archive is in the custom format of pg_dump
  • -d: database

For more options look on page manpage by pg_restore.

$ man pg_restore


SQL files

In case you have a sql file to import, use this command:

$ psql -Uusername -hlocalhost -v -ddatabase < file.sql


That's all!

quarta-feira, 31 de outubro de 2018

VS Code - Switch between edit and terminal

  1. Open Keyboard Shortcuts [Ctrl + K, Ctrl + S]
  2. Search for Focus Terminal
enter image description here
  1. Set your shortcut, in my case I used Ctrl+'
Check the editor shortcut searching for Focus First Editor, default Ctrl + 1
enter image description here

terça-feira, 30 de outubro de 2018

Importing CSV files to SQLite3 database


Today we will learn how to import n CSV files to a SQLite3 database. Yes, I wrote SQLite3, not SQLite, because the import command just has inside SQLite version 3.

First of all, you need install the SQLite3.
$ sudo apt-get install sqlite3

Now, execute the SQLite3.
$ sqlite3

This is the current version installed in my machine.
$ sqlite3
SQLite version 3.8.7.1 2014-10-29 13:59:56
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite>

Set the csv mode.
sqlite> .mode csv

Here I define the separator used in my CSV files.
sqlite> .separator ';'

Now I start importing the files.
sqlite> .import /home/lucio/desenv/file1.csv table1
sqlite> .import /home/lucio/desenv/file2.csv table2
sqlite> .import /home/lucio/desenv/file3.csv table3

Ok, I only imported 3 files, but you can import as many as you want.

You can check the tables created.
sqlite> .table
table1     table2     table3

Now, I save the tables in a sqlite file.
sqlite> .backup main my_database.db

And finish! I hope I was helpful.