Have more than 100 SQL files swollen? Importing a database row by line is certainly a foolish thing to do, but I almost did it ...
Online first find the method is: Write a xxx.sql file, inside each line is the source *.sql ..., then in MySQL to call the source Xxx.sql, the result fails, failure reason: Error 2, cannot open file Xxxxxxxxx, probably like this. This method seems to be available on Windows, but it seems like you have to put the SQL file in the Mysql/bin directory to take effect.
The solution that was then found was to use the shell script, the script source http://www.linuxidc.com/Linux/2015-01/111175.htm
Script code
#!/bin/bash
File_path= "//////////" #要导入的sql文件夹
host= "localhost" #要导入的mysql主机
Username= "Root" #mysql的用户名
password= "Root" #mysql的密码
Dbname= "xxxx" #mysql的数据库名
Mysql_source () {
For file_name in ' Ls-a $ '
Do
If [-F "$1$file_name"];then
command= "Source $1$file_name"
Mysql-h${host}-u${username}-p${password} ${dbname}-e "$command"
Done
}
Mysql_source $file _path
I put the inside time some things to go, have a moment what is can let oneself see something, actually a bunch of notice and error is already enough to see ... Then just take it and use it.
SQL file batch import MySQL database