Firstly, we will truncate the table in order to make the concepts clear and understanding better. Let us try importing this content in the workbench.Consider the following CSV file that has the same name as earlier but different contents than previous with developer names Mahesh, Suresh, Ganesh, and Saheeh – Let us look at how we can import the contents of the CSV file into the table in workbench with the help of an example. Note that in MySQL using the command-line, we can import the contents of the CSV file into the table contents by using the LOAD DATA INFILE statement. There is also the provision to import the contents of the CSV file into the table contents in Workbench by simply clicking on the import button and then specifying the path and name of the file. Importing data from CSV to Table Contents in Workbench To confirm whether the imported data of the CSV got inserted in the table properly, let us retrieve the contents of the developers’ table and compare them with the CSV file we had earlier using the following query statement – We can see that four rows were affected and all the four rows got inserted successfully without any warning or error. To import resultset from CSV file we will make the use of LOAD DATA INFILE clause as shown below – LOAD DATA INFILE '' ![]() ) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=latin1 `developer_id` int(11) NOT NULL AUTO_INCREMENT, ![]() Let us create the developer’s named table in our database educba that will hold all the above data – CREATE TABLE `developers` ( Suppose that I have a certain CSV file that is created in Microsoft Excel or LibreOffice Calc named R_developers_cmd.csv and it contains the following contents in it as shown below Importing Using command-line MySQL queriesīefore importing from CSV format, we need to make sure that the table with the same number and type of the columns exist in the database for which we are trying to import the data with matching columns exists and the user has to insert permission for that table and file permissions. In this article, we will learn how we can make use of the LOAD DATA INFILE statement to import the data to MySQL database and its table contents from any CSV format using the command-line MySQL shell and we can import the data to MySQL tables from CSV format when we are using the MySQL Workbench editor with the help of an example.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |