Answer the question
In order to leave comments, you need to log in
How correctly to transfer CommandText?
Good day. I can't figure out the syntax of the database import request.
The MySql database is installed locally. If I do all the actions with my hands, everything works.
The problem is in quotes, Powershell swears that not all quotes and apostrophes are closed.
MySQL expression
LOAD DATA LOCAL INFILE '"$Путь к файлу"' INTO TABLE `bga` FIELDS ENCLOSED BY '"' TERMINATED BY ';' LINES TERMINATED BY '\n' IGNORE 1 LINES;
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data")
$dir = 'C:\Temp\1'
$dir2 = 'C:\Temp\2'
$dbusername = 'root'
$dbpassword = '123456'
$dbname = 'curamed'
$MySQLHost = 'localhost'
$connStr ="server=localhost;database=" + $dbname + ";Persist Security Info=false;user id=" + $dbusername + ";pwd=" + $dbpassword + ";"
$conn = New-Object MySql.Data.MySqlClient.MySqlConnection($connStr)
$conn.Open()
foreach ($i in ls -name $dir\*.csv)
{
Write-Host "$i"
$file_content = Get-Content "$dir\$i";
[System.IO.File]::WriteAllLines("$dir2\$i", $file_content);
Remove-Item "$dir\$i"
conn.CommandText = "LOAD DATA LOCAL INFILE '"$dir2\$i"' INTO TABLE `bga` FIELDS ENCLOSED BY '"' TERMINATED BY ';' LINES TERMINATED BY '\n' IGNORE 1 LINES;"
$conn.ExecuteNonQuery()
}
$conn.Close()
Die Zeichenfolge hat kein Abschlusszeichen: '.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question