This article focuses on MySQL import and export. the actual operation steps of the SQL file, including how to set the command line mode of the MySQL database and how to enter the MySQL database using the command line, etc.
MySQL Import and Export. SQL file:
The procedure is as follows:
1. MySQL Command Line Mode settings:
Desktop> my computer> Properties> environment variables> New>
PATH = "; path \ MySQL \ bin;", where path is the installation PATH of MySQL.
2. A brief introduction to how to access MySQL through the command line:
1. C: \> MySQL-h hostname-u username-p
Press ENTER, and then ENTER the password. Here, hostname is the name of the server, such as localhost and username is the username of MySQL, such as root.
After entering the command line, you can directly operate MySQL.
2. A brief introduction to the MySQL command:
MySQL-> create database dbname; // CREATE a DATABASE
MySQL-> create table tablename; // CREATE a TABLE
MySQL-> show databases; // displays the database information and available DATABASES.
MySQL-> USE dbname; // select a database
MySQL-> show tables; // displays the table information, available TABLES
MySQL-> DESCRIBE tablename; // display the information of the created table
3. Export Database files from the database:
1. Export the database mydb to the e: \ MySQL \ mydb. SQL file:
Open start> RUN> Enter cmd to enter Command Line Mode
- c:\>MySQLdump -h localhost -u root -p mydb >e:\MySQL\mydb.sql
Enter the password and wait for a moment until the export is successful. You can check whether the export is successful in the target file.
2. Export mytable in mydb to the e: \ MySQL \ mytable. SQL file:
- c:\>MySQLdump -h localhost -u root -p mydb mytable>e:\MySQL\mytable.sql
3. Export the database mydb structure to the e: \ MySQL \ mydb_stru. SQL file:
- c:\>MySQLdump -h localhost -u root -p mydb --add-drop-table >e:\MySQL\mydb_stru.sql
//-H localhost can be omitted, which is generally used on a VM.
4. import data from external files to the database:
Import the SQL statements in the file into the database from e: \ MySQL \ mydb2. SQL:
1. Enter MySQL from the command line, and then run the create database mydb2 command to CREATE the DATABASE mydb2.
2. To exit MySQL, enter the command exit or quit;
3. Enter the following command in CMD:
- c:\>MySQL -h localhost -u root -p mydb2 < e:\MySQL\mydb2.sql
Then enter the password, and then OK.
5. Next, let's talk about how to solve the import file size restriction problem:
By default, the size of the MySQL imported file is limited to 2 MB. Therefore, when the file is large, it cannot be imported directly. The solution to this problem is as follows:
1. Modify related parameters in php. ini:
There are three parameters that affect the size of the MySQL import file:
- memory_limit=128M,upload_max_filesize=2M,post_max_size=8M
Modify upload _......
The above content is an introduction to the MySQL Import and Export. SQL file. I hope you will find some gains.