Found 6705 Articles for Database

What are some frequently used mysqlimport options while uploading the data into MySQL table through command line?

usharani
Updated on 27-Feb-2020 07:32:01

163 Views

mysqlimport can be run with a number of options. Followings are some options for mysqlimport and their effect on import.OptionAction-r or –replaceCause imported rows to overwrite existing rows if they have the same unique key value.-i or –ignoreIgnore rows that have the same unique key value as existing rows.-f or –forceForce mysqlimport to continue inserting data even if errors are encountered.-l or --lock-tablesLock each table before importing (a good option on a busy server).-d or –deleteEmpty the table before inserting.--fields-terminated- by='char'Specify the separator used between values of the same row, default \t (tab).--fields-enclosed- by='char'Specify the delimiter that encloses each field; ... Read More

How can we upload data into multiple MySQL tables by using mysqlimport?

varun
Updated on 20-Jun-2020 10:37:03

413 Views

With the help of mysqlimport we can upload data into multiple MySQL tables. It is illustrated in the example below −ExampleSuppose we want to upload the following data from two data files namely student1_tbl.txt −1     Saurav     11th 2     Sahil      11th 3     Digvijay   11thAnd House.txt1   Furniture 2   Television 3   RefrigeratorFollowings are MySQL tables into which we want to upload the above data −mysql> DESCRIBE Student1_tbl; +--------+-------------+------+-----+---------+-------+ | Field  | Type        | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | RollNo | int(11) ... Read More

How can we upload data into MySQL tables by using mysqlimport?

Prabhas
Updated on 20-Jun-2020 10:38:34

343 Views

For uploading the data into MySQL tables by using mysqlimport we need to follow following steps −Step-1 − Creating the tablefirst of all, we need to have a table in which we want to upload the data. We can use CREATE TABLE statement for creating a MySQL table. For example, we created a table named ‘student_tbl’ as follows −mysql> DESCRIBE Student_tbl; +--------+-------------+------+-----+---------+-------+ | Field | Type         | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | RollNo | int(11)     | YES  |     | NULL    |       | | ... Read More

How can we transfer information between MySQL and data files through command line?

seetha
Updated on 07-Feb-2020 05:31:01

182 Views

Transferring the information between MySQL and data files mean importing data from data files into our database or exporting data from our database into files. MySQL is having two commands that can be used to import or export data between MySQL and data files through the command line −mysqlimport Actually, mysqlimport command reads a spread of data formats, including comma-and tab-delimited, and inserts the information into a database. In other words, we can say that it provides a command-line interface for importing the data i.e. command-line interface to the LOAD DATA INFILE statement. Its syntax would be as follows −SyntaxMysqlimport [options] ... Read More

How can we tackle MySQL error ‘ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement’ while importing or exporting the data?

Abhinaya
Updated on 07-Feb-2020 05:31:58

1K+ Views

MySQL throws this error because of the two reasons, either no directory is specified under --secure--file--priv variable or we are giving the wrong path in our query while importing or exporting the data. To tackle this error we must have to check the value of –secure—file—priv variable by following query −mysql> Select @@global.secure_file_priv; +---------------------------+ | @@global.secure_file_priv | +---------------------------+ | C:\mysql\bin\mysql-files\ | +---------------------------+ 1 row in set (0.00 sec)We can see there is path under secure_file_priv variable and all the files would be created under this directory when we export the data.But, if the above command shows NULL as result then ... Read More

How can we store any other value than N in CSV file if we export the data to CSV file from a table which contains a NULL value(s)?

Nancy Den
Updated on 07-Feb-2020 05:36:23

232 Views

If we want to store any other value than \N in CSV file on exporting the data to CSV file from a table which contains NULL value(s) then we need to replace \N values with other value by using IFNULL statement. To illustrate it we are taking the following example −ExampleSuppose if we want to export the values of the table ‘student_info’ having the following data −mysql> Select * from Student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | ... Read More

How MySQL evaluates if we export the data to CSV file from a table which contains a NULL value(s)?

Daniol Thomas
Updated on 07-Feb-2020 05:38:28

352 Views

If we export the data from a table having NULL values then MySQL will store \N in CSV file for the record MySQL table having NULL values. It can be illustrated with the help of the following example −ExampleSuppose if we want to export the values of the table ‘student_info’ having the following data −mysql> Select * from Student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Chandigarh | Literature | | 125  | Raman   | ... Read More

How can we export data to a CSV file along with columns heading as its first line?

Krantik Chavan
Updated on 07-Feb-2020 05:41:38

200 Views

For adding the column values we need to use UNION statement. It can be demonstrated with the help of the following example −ExampleIn this example data from student_info will be exporting to CSV file. The CSV file will have the first line as the name of the columns.mysql>(SELECT 'id', 'Name', 'Address', 'Subject')UNION(SELECT id, Name, Address, Subject From student_info INTO OUTFILE 'C:/mysql/bin/mysql-files/student_25.CSV' FIELDS ENCLOSED BY '"' TERMINATED BY ';' ESCAPED BY '"' LINES TERMINATED BY '\r'); Query OK, 7 rows affected (0.04 sec)After executing the above query MySQL creates Student_25.CSV file which have the following values −id;    "Name";     ... Read More

How can we export data to a CSV file whose filename name contains timestamp at which the file is created?

Nishtha Thakur
Updated on 07-Feb-2020 05:42:46

561 Views

Sometimes we need to export data into a CSV file whose name has a timestamp at which that file is created. It can be done with the help of MySQL prepared statement. To illustrate it we are using the following example −ExampleThe queries in the following example will export the data from table ‘student_info’ to the CSV file having a timestamp in its name.mysql> SET @time_stamp = DATE_FORMAT(NOW(), '_%Y_%m_%d_%H_%i_%s'); Query OK, 0 rows affected (0.00 sec) mysql> SET @FOLDER = 'C:/mysql/bin/mysql-files'; Query OK, 0 rows affected (0.00 sec) mysql> SET @FOLDER = 'C:/mysql/bin/mysql-files/'; Query OK, 0 rows affected ... Read More

How MySQL SUM() function evaluates if it got the column, having character data type, as its argument?

Chandu yadav
Updated on 07-Feb-2020 05:43:43

159 Views

MySQL SUM() function will return 0, rather than NULL, along with a warning on getting the character type column as its argument. Following example using data from table named ‘Social’ will illustrate it −Examplemysql> Select * from Social; +------+-------+ | Id   | Name  | +------+-------+ | 100  | Rahul | +------+-------+ 1 row in set (0.00 sec) mysql> Select SUM(Name) From Social; +-----------+ | SUM(Name) | +-----------+ | 0         | +-----------+ 1 row in set, 1 warning (0.00 sec)

Advertisements