Windows cmd line and MySQL

from the Artful MySQL Tips List


To use MySQL tools on the Windows command line, you need a convenient way to access them without having to type the full path to MySQL executables. The simplest way is to add the bin folder of the MySQL installation to the system path. That's done in the Advanced tab of the Windows System Properties dialog. Click on Environment variables, in the System variables area of what pops up, select Path, click Edit, add ...

c:program filesmysqlmysql 5.7bin

or whatever your installation folder is, with the suffix bin, and click OK. On Windows versions before 8, you may need to reboot before the Windows command line tool can find the updated path. Now when you open a command line window as administrator, and type ...

mysqld --help | more

you should see MySQL server help, one screen at a time. Now you have access to the MySQL server, client programs and utilities.

One other convenience note: the command line is more useful if set to 50 lines high, and as wide as your screen allows.

To start the service for the first time, issue ...

mysqld --defaults-file="c:program filesmysqlmysql 5.7my.ini" --console –-skip-grant-tables 

If there are errors, you will see the in this window; fix them and try again. Once the server starts normally, the window will freeze. Open another command line window to run the mysql client ...

mysql -uroot -pPWD

substituting your MySQL password for PWD.

Once you've established that the server is running, in the second command line window issue ...

mysqladmin shutdown

To use the command line window to start the MySQL service that's been created by the MySQL installer, isue ...

net start mysqld

or whatever service name has been set by your installation.

Windows also has a powerful command line service control utility, sc.exe for starting, stopping and configuring Windows services. To see its help screen, run ...

sc /? | more

Full help for this utility is at https://technet.microsoft.com/en-us/library/bb490995.aspx?f=255&MSPPError=-2147217396. The MySQL manual has a page about using this utility, https://dev.mysql.com/doc/refman/5.7/en/windows-start-service.html.

Return to the Artful MySQL Tips page