Results 1 to 5 of 5

Thread: How to Insert data into MySQL table

  1. #1
    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...

  2. #2
    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");

  3. #3
    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.

  4. #4
    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';
    ?>

  5. #5
    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.

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,514,006.10072 seconds with 17 queries