Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 14-04-2009
Member
 
Join Date: Apr 2009
Posts: 69
How to Insert data into MySQL table

Hello programming gurus,

I am novice for learning MySQL, and I wanted to know how to insert data into MySQL table, that table should contain the number of table fields,and also i should be able to insert at 25-30 records at a time. And the program should be so capable of inserting number of fields later on.

Thanks for your help...
Reply With Quote
  #2  
Old 14-04-2009
Member
 
Join Date: Mar 2008
Posts: 258
Re: How to Insert data into MySQL table

Inserting data into employee_data table with employee.dat file
On Windows

1. Move the file to c:\mysql\bin.
2. Make sure MySQL is running.
3. Issue the following command
mysql employees <employee.dat

On Linux

1. Migrate to the directory that contains the downloaded file.
2. Issue the following command
mysql employees <employee.dat -u username -p
3. Enter your password.


The INSERT SQL statement impregnates our table with data. Here is a general form of INSERT.

Code:
INSERT into table_name (column1, column2....)
values (value1, value2...);
where table_name is the name of the table into which we want to insert data; column1, column2 etc. are column names and value1, value2 etc. are values for the respective columns.

The following statement inserts the first record in employee_data table.

Code:
INSERT INTO employee_data
(f_name, l_name, title, age, yos, salary, perks, email)
values
("Manish", "Sharma", "CEO", 28, 4, 200000, 
50000, "manish@bigne..com");
Reply With Quote
  #3  
Old 14-04-2009
Member
 
Join Date: Mar 2008
Posts: 232
Re: How to Insert data into MySQL table

The purpose of the SQL INSERT statement is to add new rows of data to a specified database table. Using the INSERT statement, it is possible to insert a complete row, a partial row, multiple rows or rows generated as the result of a database query.

Inserting a Complete Row

Code:
INSERT INTO products(
     product_id,
     product_name,
     product_description,
     product_location,
     product_quantity)
VALUES(
     NULL,
     'CD-RW Model 4543',
     'CD Writer',
     'Shelf 4B',
     10
};
Note that the product_id is specified as NULL. This is because the product_id in our imaginary table is set to AUTO_INCREMENT so we do not specifically set this. Instead, the MySQL database engine will automatically create a new value for us.
Reply With Quote
  #4  
Old 14-04-2009
Member
 
Join Date: Jan 2006
Posts: 211
Re: How to Insert data into MySQL table

Here I will also provide you details for inserting data through PHP.

Inserting data to MySQL is done by using mysql_query() to execute INSERT query. Note that the query string should not end with a semicolon. Below is an example of adding a new MySQL user by inserting a new row into table user in database mysql :

Example : insert.php
Source code : insert.phps

Code:
<?php
include 'library/config.php';
include 'library/opendb.php';

mysql_select_db($mysql);
$query = "INSERT INTO user (host, user, password, select_priv, insert_priv, update_ priv) VALUES ('localhost', 'phpcake', PASSWORD('mypass'), 'Y', 'Y', 'Y')";

mysql_query($query) or die('Error, insert query failed');

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert query failed');

include 'library/closedb.php';
?>
Reply With Quote
  #5  
Old 04-10-2009
Member
 
Join Date: Oct 2009
Posts: 1
Re: How to Insert data into MySQL table

Quote:
Originally Posted by Khushal View Post
Inserting data into employee_data table with employee.dat file
On Windows

1. Move the file to c:\mysql\bin.
2. Make sure MySQL is running.
3. Issue the following command
mysql employees <employee.dat
This isn't working for me. When I use MySQL Command Line Client, and type "mysql employees <employee.dat" I get the "->" prompt indicating that my command is incomplete, if I try to add a ; I get the following error "ERROR 1064 (42000): You have an error in your SQL syntax [..]". Since I am already in mysql (the prompt is "mysql>") I have tried both "employees <employee.dat", and "employees <employee.dat;", with the same results.

Last edited by cura : 04-10-2009 at 04:51 AM.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to Insert data into MySQL table"
Thread Thread Starter Forum Replies Last Post
Insert data from an Excel file into MySQL. Antonio1 Windows Software 3 24-11-2009 01:51 AM
How to copy one table data into another table directly? ComPaCt Software Development 3 22-09-2009 03:54 PM
Insert Images in MySQL from FTP MeteoWatch Software Development 2 02-07-2009 01:06 AM
Batch insert on MySQL is possible Shreevats Software Development 3 16-05-2009 06:13 PM
how to insert a image in mysql cnu0870 Software Development 5 28-04-2009 05:15 PM


All times are GMT +5.5. The time now is 09:17 PM.