[root@kvm3 ~]# mycli -S /var/lib/mysql/mysql.sock -uroot -p123qwe mariadb 10.3.11-MariaDB mycli 1.20.1 Chat: https://gitter.im/dbcli/mycli Mail: https://groups.google.com/forum/#!forum/mycli-users Home: http://mycli.net Thanks to the contributor - bjarnagin
mariadb root@localhost:(none)> use dyw; You are now connected to database "dyw" as user "root" Time: 0.002s
SELECT ... INTO OUTFILE
匯出資料到檔案。
mariadb root@localhost:dyw> select * from animals into outfile '/tmp/animals.txt '; Query OK, 4 rows affected Time: 0.002s
mariadb root@localhost:dyw> select * from animals into outfile '/tmp/animals.txt '; (1086, "File '/tmp/animals.txt' already exists")
[root@kvm3 ~]# find /tmp/systemd-private-* -name animals.txt /tmp/systemd-private-5703fd24db4b4a06810bcbdcbf47c485-mariadb.service-3apdPV/tmp/animals.txt
[root@kvm3 ~]# find /tmp/systemd-private-* -name animals.txt | xargs cat - 1 dog 4 2 cat 4 3 chicken 2 15 bird 2
SELECT ... INTO OUTFILE
並指定格式匯出資料到檔案。
mariadb root@localhost:dyw> select * from animals into outfile '/tmp/animals1.tx t' fields terminated by ',' enclosed by '"' lines te rminated by '\r\n'; Query OK, 4 rows affected Time: 0.003s
[root@kvm3 ~]# find /tmp/systemd-private-* -name animals1.txt | xargs cat - "1","dog","4" "2","cat","4" "3","chicken","2" "15","bird","2"
[root@kvm3 ~]# grep PrivateTmp /etc/systemd/system/multi-user.target.wants/mariadb.service PrivateTmp=false [root@kvm3 ~]# systemctl daemon-reload [root@kvm3 ~]# systemctl restart mariadb.service