Quantcast
Channel: Active questions tagged powershell-3.0 - Stack Overflow
Viewing all articles
Browse latest Browse all 122

PowerShell script to upload multiple tables into MySQL workbench DB

$
0
0

I tried using the below script to achieve the solution programmatically instead of manually using the MySQL workbench window to import from self-Contained File located under a folder in C:\ drive>

# Importing Tables into the MySql database:$mysql_server = "localhost"$mysql_user = "root"$mysql_password = "abcde"$dbName = "xxxxx" # need multiple .sql tables located in a particular c: drive folder[void][system.reflection.Assembly]::LoadFrom("C:\Program Files (x86)\MySQL\MySQL Installer for Windows\MySql.Data.dll")$Connection = New-Object -TypeName MySql.Data.MySqlClient.MySqlConnection$Connection.ConnectionString = "SERVER=$mysql_server;DATABASE=$dbName;UID=$mysql_user;PWD=$mysql_password"$Connection.Open()$sql = New-Object MySql.Data.MySqlClient.MySqlCommand$sql.Connection = $Connection$sql.CommandText = "LOAD DATA LOCAL INFILE 'C:/path/to/*.sql' # desire to get all the .sql TABLEs in particular folder and upload them with ps, instead of using MySQL workbench GUI that uploads from C:\...\export.sql$sql.ExecuteNonQuery()$Connection.Close()

Tried running the code as a batch file.cmd but this couldn't upload the tables. It appeared to have worked if used for .sql files but not the the requires tables that contain those files.Would need help to rewrite the script in -$sql.CommandText to capture all the required tables


Viewing all articles
Browse latest Browse all 122

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>