Category Archives: Database

Add user in mysql

The classic three-liner for adding a MySQL user, run from a mysql shell connected as root or another account with the CREATE USER privilege. Replace each placeholder with your own value. 123CREATE USER ‘YOUR_USER_NAME’@’CONNECTING_FROM_WHERE’ IDENTIFIED BY ‘THIS_USER_PASSWORD’; GRANT ALL PRIVILEGES … Continue reading

Posted in MySQL | Leave a comment

Calling a mysql query from linux or dos command line

There are times when you want to call a mysql command from the bash or dos script then call this script in a scheduler (cron job). The example below will show you how to do so. 1mysql -uYOURUSERNAME -pYOURPASSWORD -DYOURDATABASE … Continue reading

Posted in Database, Linux, MySQL | Leave a comment

MySQL Backup and Restore – Using Command Line

Here’s how you back up a database from the command line. The first line is the backup, the second is the restore. These commands work on both Windows and Linux. On Windows you might want to add the MySQL bin … Continue reading

Posted in Database, Linux, MySQL | Leave a comment

Vacuum the Whole Database in Postgres

Postgres comes with a functionality called vacuum. Vacuum is intended to cleanup dead tuples or rows. This is how you cleanup the entire DB in PostgreSQL 1/usr/pg9/bin/vacuumdb –full –port=5433 –username=YOUR_USERNAME –password DB_NAME

Posted in Database, PostgreSQL | Leave a comment

Backup and Restore Postgres Using pg_dump and psql

This is how you backup your Postgres Database To Backup 1pg_dump –host=localhost –port=5432 –username=postgres –file=YOUR_FILENAME.sql YOUR_DB_NAME There are other options such as if you’re interested only on the structure then you can add: 1pg_dump –host=localhost –port=5432 –username=postgres –schema-only –format=p –create … Continue reading

Posted in Database, PostgreSQL | Leave a comment

Setting Session Authorization and Search Path

SET SESSION AUTHORIZATION jane; SET search_path = schema1,schema2, schema3; SELECT * FROM any_table_in_schema_1_2_or_3;

Posted in Database, PostgreSQL | Leave a comment

Implicit Casting in PostgreSQL

12CREATE CAST(integer AS character varying) WITH INOUT AS IMPLICIT; CREATE CAST (character varying AS integer) WITH INOUT AS IMPLICIT;

Posted in Database, PostgreSQL | Leave a comment

Integer Array Casting in PostgreSQL

123456– Rule: "_DELETE" ON sometable — DROP RULE "_DELETE" ON sometable; CREATE OR REPLACE RULE "_DELETE" AS     ON DELETE TO sometable DO INSTEAD  DELETE FROM _sometable  WHERE _sometable.account_id = old.account_id AND (old.domain_id = ANY ((( SELECT get_visible_domains(‘DELETE’::text) AS … Continue reading

Posted in Database, PostgreSQL | Leave a comment

Tracing PostgreSQL Error Log

1/pgsql/dev-db/tail -f postgresql.log

Posted in Database, Linux, PostgreSQL | Leave a comment

Reset Sequence using PostgreSQL

1SELECT setval(‘YOUR_SEQUENCE_NAME’, (SELECT MAX(id) FROM YOUR_TABLE_NAME));

Posted in Database, PostgreSQL | Leave a comment