Skip to content
Advertisement

how to create schema in mysql and how to import existing record into the database?

I have file with name data that contain information like in my linux machine

I have created a database in Mysql with name “invaliduser” and inside that i have create table “invalidlog” and i created a schema like this

when i am trying to import the data file in mysql with the following command

it is showing me error:

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘2 Mar 1 1234 141.98.80.59 1 Mar 1 1234 171.239.249.233 5 Mar 1 admin’ at line 1

This is a correct way to create schema?

Advertisement

Answer

You cannot simply import the data into your table, you will need to generate valid SQL syntax from the file. This can be done with awk:

Set up a variable sinq to be a single quote and then use this along with the space separated fields to generate the required sql.

Output:

The awk command can then be integrated with mysql:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement