myhelp:sql
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| myhelp:sql [2022/12/01 09:37] – created - external edit 127.0.0.1 | myhelp:sql [2024/10/05 07:51] (current) – [mySQL / MariaDB] ulrich | ||
|---|---|---|---|
| Line 11: | Line 11: | ||
| sqlite> UPDATE T_names SET birthyear=1997 WHERE name = 'Jack Doe'; | sqlite> UPDATE T_names SET birthyear=1997 WHERE name = 'Jack Doe'; | ||
| sqlite> SELECT * FROM T_names LIMIT 1; | sqlite> SELECT * FROM T_names LIMIT 1; | ||
| + | </ | ||
| + | |||
| + | ====== mySQL / MariaDB ====== | ||
| + | < | ||
| + | CREATE DATABASE IF NOT EXISTS meineDB; | ||
| + | CREATE USER ' | ||
| + | GRANT ALL PRIVILEGES ON meineDB . * TO ' | ||
| + | </ | ||
| + | |||
| + | Grant Access from remote IP (10.11.12.13) | ||
| + | < | ||
| + | GRANT ALL ON meineDB.* to ' | ||
| </ | </ | ||
| Line 32: | Line 44: | ||
| SELECT something, anything FROM T_table WHERE something != ' | SELECT something, anything FROM T_table WHERE something != ' | ||
| SELECT something, anything FROM T_table WHERE something LIKE ANY (ARRAY[' | SELECT something, anything FROM T_table WHERE something LIKE ANY (ARRAY[' | ||
| + | </ | ||
| + | Create a new DB and User and change DB-Owner | ||
| + | < | ||
| + | CREATE DATABASE mynewdb; | ||
| + | CREATE USER myuser WITH PASSWORD ' | ||
| + | ALTER DATABASE mynewdb OWNER TO myuser; | ||
| + | </ | ||
| + | Copying PostgreSQL database to another server | ||
| + | < | ||
| + | pg_dump -C mynewdb | psql -h db.server.host -U myuser mynewdb | ||
| </ | </ | ||
| + | Original command from [[https:// | ||
| + | |||
| + | ===== Enable remote connections ===== | ||
| + | - Find your postgresql.conf < | ||
| + | - Open the postgresql.conf < | ||
| + | listen_addresses = ' | ||
| + | - Find your pg_hba.conf (on RHEL based distros: / | ||
| + | - Add the following lines < | ||
| + | host all | ||
| + | host all | ||
| + | - Restart the DBMS < | ||
| + | |||
| + | ===== A method to get the lastest timestamp ===== | ||
| + | From my point of view I've a good and a bad example | ||
| + | |||
| + | The good example: | ||
| + | < | ||
| + | WHERE time_stamp = (SELECT MAX(time_stamp) FROM table);</ | ||
| + | |||
| + | The bad example: | ||
| + | < | ||
| + | WHERE time_stamp = (SELECT time_stamp FROM table ORDER BY time_stamp DESC NULLS LAST LIMIT 1);</ | ||
| + | |||
| + | ===== Other usefull stuff ===== | ||
| + | Switch off the pages from CLI(shell) | ||
| + | < | ||
| + | |||
| + | |||
| + | Copy a SELECT to a CSV from CLI(shell) | ||
| + | < | ||
| + | sudo -u postgres psql -d database -c "COPY (SELECT | ||
| + | GROUP BY something) TO '/ | ||
| + | </ | ||
| + | |||
| + | {{tag> | ||
myhelp/sql.1669887455.txt.gz · Last modified: by 127.0.0.1
