Home>Article>Topics> How to import database into mysql in php

How to import database into mysql in php

藏色散人
藏色散人 Original
2020-10-26 09:54:18 5417browse

php method to import the database into mysql: 1. Import the MySQL database through CMD; 2. Import the MySQL database through Navicat for MySQL; 3. Execute the SQL file through PHP to import the MySQL database.

How to import database into mysql in php

Recommended: "mysql video tutorial" "php mysql"

Import MySQL database through CMD

Run cmd, enter "mysql -u username -p password" in the cmd command prompt to enter the MySQL interface, enter "show databases;" View the created database. Here I created a database named test (new database name: CREATE DATABASE database name).

How to import database into mysql in php

Enter "use test (database name)" to start using this database. Enter "show tables;" to view the created database tables. Here we can see the current No data table is created in the test database.

How to import database into mysql in php

Next we start to import the sql file. Here I have added several new data tables. Enter the command "source d:/blog.sql (path to the sql file)" ", pay attention to your file path here, replace all "\" with "/", and then check through "show tables;" to see the database table shown on the right side of the figure below.

How to import database into mysql in php

Import MySQL database through Navicat for MySQL

If you find it troublesome, you can use the third-party management tool Navicat for MySQL to import sql files , use Navicat for MySQL to connect to the database, select the corresponding database name, then drag the sql file into the table, and then click Start to execute the new table command in sql. After completion, close and refresh the Navicat for MySQL table to see The table information we just imported.

How to import database into mysql in php

Execute SQL files through PHP to import the MySQL database

If you are using PHP to develop, you can also use PHP to implement To write the SQL file into the MySQL database, here we need to split the SQL file, group the SQL statements by the ";" sign, and then manually connect to the database (here we need to provide 4 parameters, namely domain name, user name, password, Database name). To write sql statements, we can use foreach to loop sql data to execute sql statements in batches. Finally, remember to close the database.

How to import database into mysql in php

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

Statement:
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