Using the clauses FIELDS and LINES you can choose the field and line terminators in the file from which you need to load data. If you verify the contents of the DEMO table you can observe the records in it as − Records: 4 Deleted: 0 Skipped: 0 Warnings: 0 Mysql> load data infile "directory path/test.txt" into table DEMO Mysql> CREATE TABLE DEMO (NAME VARCHAR(20)) Īnd if we have a file named test.txt with contents as −įollowing query loads the contents of the test.txt file in the above created table − GRANT ALL ON test.* TO we have created a table using the CREATE statement as shown below − Make you grant file (or, all) privileges to the database in which your table exist − Mysql> SHOW GLOBAL VARIABLES LIKE 'local_infile' īefore you load data from a file make sure you have enabled local_infile option as − Syntaxįollowing is the syntax of the above statement −īefore discussing some examples first of all, let us verify whether loading local data is enabled, if not you can observe the local_infile variable value as − If you use the LOCAL clause, you can upload the local files contents int to a table. Using the LOAD DATA statement, you can insert the contents of a file (from the server or a host) into a MySQL table.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |