How to Connect to MySQL With PowerShell

Written by jim campbell
  • Share
  • Tweet
  • Share
  • Email

Windows Powershell provides you with a command line utility to automate some features in Windows, including a connection to a MySQL server. Powershell lets you run queries from a command line without the need for third party software. You use the MySQL DLL file on the server to connect to the database. After you connect to MySQL you can manipulate the data and tables from the command line.

Skill level:

Things you need

  • MySQL connector installed

Show MoreHide


  1. 1

    Click the Windows "Start" button and type "MySQL.Data.dll" in the search text box. Press "Enter" to do a search for the file. You need the location of the file to connect from Powershell. In the results window take note of the directory where the DLL file is located.

  2. 2

    Click the Windows "Start" button and select "All Programs. Click "Accessories" then click "Windows PowerShell." Click the "Windows PowerShell" icon to open the command line tool.

  3. 3

    Type or copy the following text into the Powershell window and press "Enter":


    Replace "C:\location" with the location of the DLL file.

  4. 4

    Type the following code to create the connection to the server so you can query the database tables:

    run-MySQLQuery -ConnectionString "Server=localhost;Uid=user;Pwd=pw;database=mydb;"

    Replace "user" and "pw" with the user name and password needed to connect to the database server. Replace "mydb" with the name of the database. This code connects to the database so you can now run queries or view security information for the MySQL server.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.