How to input data to a MySQL table

Source: Internet
Author: User

After creating a database and a table, we first think of inputting data into the database table. Next we will discuss how to add data to the database:

1. The common method is insert statements.

Reference content is as follows:
Insert into tablename values (value1, value2 ,...)
  
Insert into tablename (fieldname1, fieldname2,...) values (value1, value2 ,...)
  
Insert into tablename set fieldname1 = value1,
Fieldname2 = value2 ,...
  
Insert into tablename (fieldname1, fieldname2) select fieldname1,
Fieldname2 from tablename1

In addition, we can use the insert statement to insert several rows into a table at the same time.

Reference content is as follows:
Insert into tablename values (...),(...),...

2. in the MySQL environment, we can also use the load data statement to read the DATA in the file into the table. generally, this file is directly read by the server on the host. therefore, you must have the file permission and the file must be fully readable. if your version is new enough, you can provide a local file. As you read the file from the client and transmit the content to the server, you do not need the file permission.

If you do not provide a local address, the server locates it as follows:

(1) If your filename is an absolute path, the server will start searching for the file from the root directory.

(2) If your filename is a relative path, the server will start searching for the file from the database data directory.

If you provide local, the file will be located as follows:

(1) If your filename is an absolute path, the client will start searching for the file from the root directory.

(2) If your filename is a relative path, the client will start searching for the file from the current directory.

Specific format:

Reference content is as follows:
Load data [LOCAL] INFILE 'filename'
Into table tablename import_options
[(Fieldname_list)]

The import options syntax is:

Reference content is as follows:
Fields
  
Terminated by 'Char'
  
Enclosed by 'Char'
  
Escaped by 'Char'
  
Lines
  
Terminated by 'string'

  • 2 pages in total:
  • Previous Page
  • 1
  • 2
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.