There are many purposes for exporting MySQL data, such as database backup, table structure export, table data export, and data analysis. Part1 select into outfile Let's start with the shortest and most powerful select into outfile, which is the most commonly used data collection method for small database analysis. The specific syntax is as follows: [Select statement] is a classic query SQL, which can specify columns, where conditions, group, order, limit, etc. [Export file name] is the full path of the target file. Due to the permission problem of MySQL account, we usually export the file to a temporary directory, such as /tmp/mysql/user/201810.csv 【Export parameters】
for example: select * from platform_user into outfile '/tmp/mysql/user/201810.csv' fields terminated by ',' enclosed by '"' lines starting by '\r' terminated by '\n'; If the exported data involves Chinese characters, you may see garbled characters when you open the csv file. To handle garbled characters, first make sure that the database supports Chinese (usually set UTF8 encoding) vim /etc/my.cnf, add the following options: [client] default-character-set=utf8 [mysqld] character_set_server=utf8 [mysql] default-character-set=utf8 Even if the database is already in utf8, the exported file may still contain garbled characters when downloaded locally. Are the results seen by less and tail on the server normal? Part 2 mysqldump export data As a developer or operation and maintenance personnel, mysqldump is used more frequently because it can do more things. mysqldump is a logical backup tool because it exports results, mostly in the form of SQL, and does not record the data change process. Regarding physical backup, you can refer to a book called "MySQL Technology Insider", which has a detailed description. The syntax of mysqldump is very simple, namely mysqldump [options]> dump.sql However, there are many optional parameters for options. The manual divides them into several categories, including link option, file option, data definition DDL option, Debug option, internationalization option, cluster Replication option, format option, performance option, transaction option, etc. Interested students can refer to the definition in the MYSQL official manual. Here we only introduce several common application scenarios. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to monitor multiple JVM processes in Zabbix
>>: How to mount a disk in Linux
1 Introduction Apache Storm is a free, open sourc...
1. RPM version installation Check if there are ot...
Preface I recently encountered this requirement a...
If you accidentally modify the source.list conten...
This article example shares the specific code of ...
<meta name="viewport" content="w...
Table of contents 1. What is dynamic typing? 2. D...
Table of contents 1. Function definition 1.1 Func...
1. What is SQL injection? Sql injection is an att...
Solution to the data asymmetry problem between My...
I have searched various major websites and tested...
Sometimes it is necessary to perform simple verif...
:is dynamic component Use v-bind:is="compone...
Table of contents 1. Data Source 2. Overall ranki...
Recently, there is a need to automatically search...