User Tools

Site Tools


myhelp:sql

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
myhelp:sql [2023/08/28 07:01] ulrichmyhelp: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;
 +</code>
 +
 +====== mySQL / MariaDB ======
 +<code>
 +CREATE DATABASE IF NOT EXISTS meineDB;
 +CREATE USER 'benutzer'@'localhost' IDENTIFIED BY 'passwort';
 +GRANT ALL PRIVILEGES ON meineDB . * TO 'benutzer'@'localhost';
 +</code>
 +
 +Grant Access from remote IP (10.11.12.13)
 +<code>
 +GRANT ALL ON meineDB.* to 'benutzer'@'10.11.12.13' IDENTIFIED BY 'passwort' WITH GRANT OPTION;
 </code> </code>
  
Line 71: Line 83:
 Switch off the pages from CLI(shell) Switch off the pages from CLI(shell)
 <code>sudo -u postgres psql -P pager=off -d database -c "SELECT something FROM table;"</code> <code>sudo -u postgres psql -P pager=off -d database -c "SELECT something FROM table;"</code>
 +
 +
 +Copy a SELECT to a CSV from CLI(shell)
 +<code>
 +sudo -u postgres psql -d database -c "COPY (SELECT  something, other_stuff FROM table 
 +GROUP BY something) TO '/tmp/result.csv' WITH CSV HEADER;"
 +</code>
 +
 {{tag>[Good2Know]}} {{tag>[Good2Know]}}
myhelp/sql.1693206063.txt.gz · Last modified: by ulrich