How to import mysql

WBOY
Release: 2023-05-18 09:02:37
Original
1485 people have browsed it

MySQL is a relational database management system that is often used for web application development and data storage. When we need to import data into MySQL, we can use the following steps.

Step 1: Create a database

First, we need to create a database in MySQL. We can create a database through the command line or tools such as MySQL Workbench.

The command line operation to create a database is as follows:

CREATE DATABASE databasename;
Copy after login

We can replace "databasename" with the database name of our choice.

Step 2: Create a table

Next, we need to create a table to store the data. We can use tools such as MySQL Workbench to create tables, or we can create them through the command line. If we want to create a table through the command line, the steps are as follows:

USE databasename; CREATE TABLE tablename ( column1 datatype, column2 datatype, column3 datatype, ..... );
Copy after login

In the above command, we need to replace "databasename" with the name of the database we created and "tablename" with the name of the database we want to create Table name, and specify the column name to be created and the corresponding data type through "column1", "column2", etc.

Step 3: Prepare data

Before importing data into MySQL, we need to prepare the data first. Data can include text files, Excel files and other formats.

In order to successfully import data into MySQL, we need to save the data in .csv or .txt format. First open the Excel table, click "File" - "Save As" - save the file format as ".csv" or ".txt" format.

Step 4: Import data

We can import data into MySQL in the following ways:

  1. Use MySQL Workbench

Open MySQL Workbench, select "Server" - "Data Import" - "Import from Self-Contained File" - select the CSV file to be imported - select the target database and table - click "Start Import".

  1. Using the command line

The operation of using the command line to import data is as follows:

LOAD DATA LOCAL INFILE 'filepath/filename.csv' INTO TABLE tablename FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY ' ';
Copy after login

In the above command, we need to change "filepath/filename. csv" is replaced with the path and name of the CSV file we want to import, "tablename" is replaced with the name of the table to which the data is to be imported, where "FIELDS TERMINATED BY" and "LINES TERMINATED BY" are used to specify the separators of columns and rows and Terminator at the end of the line.

  1. Use PHPMyAdmin

In PHPMyAdmin, select the target database and table, click "Import" - select the CSV file to be imported - set options - click " Import".

Summary

The above are the steps for importing data into MySQL. We can choose a method that suits us to import data according to our needs. When importing data, you need to pay attention to the format, path, name, delimiter, etc. of the data to ensure that the data can be correctly imported into MySQL. At the same time, we need to create the database and tables before importing data to ensure that the data can be stored correctly.

The above is the detailed content of How to import mysql. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!