myhelp:sql
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| myhelp:sql [2023/05/09 09:17] – ulrich | 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 45: | Line 57: | ||
| pg_dump -C mynewdb | psql -h db.server.host -U myuser mynewdb | pg_dump -C mynewdb | psql -h db.server.host -U myuser mynewdb | ||
| </ | </ | ||
| - | Original command from [[https:// | + | 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> | {{tag> | ||
myhelp/sql.1683623836.txt.gz · Last modified: by ulrich
