Work with MySQL terminal On our previous post, we have discussed about how to install LAMP Environment on your Windows PC easily using XAMPP. If you are a MySQL coder, or wish to learn it, then probably you have came to know about the MySQL terminal [or simply a command prompt in Windows]. Basically it is the best MySQL tool for any newbie user. You have type all your SQL Queries here manually and this way you can actually learn faster.

But opening the MySQL prompt can be a little tricky in Windows PC. As just typing “mysql” in command prompt does not work… So here is a complete guide to easily open MySQL terminal from Windows Command Prompt.


#1: Install XAMPP and locate installation Directory:

First you need to install XAMPP on your Windows PC. You can install MySQL alone if you want, but I shall recommend XAMPP for a better and easier usage. Simply follow the previous post to install it. Also Note down the installation directory.

The default installation directory is “C:\XAMPP\”. It may vary for your customized installation. So assuming this, try to locate this folder:

C:\xampp\mysql\bin\” or “~Installation Folder~\xampp\mysql\bin

where ~installation Folder~ is obviously the folder where you have selected to install XAMPP.

You should be able to find a file named, mysql.exe . This is the main MySQL Terminal.Locate mysql.exe file If you simply open it by double clicking then although a MySQL Terminal will be launched, but you won’t actually be able to modify your database, as in this way MySQL terminal does not get connected to the DB server host!

Just follow the instruction below to open the terminal properly…

#2: Open MySQL terminal from Windows Command Prompt(cmd):

  • Go to Start Menu > All Programs > Accessories > Command Prompt;
  • This will pop up the Windows CMD.
  • Now type in the following command and hit enter:
    CD C:\xampp\mysql\bin

    Change the working directory using cd

  • Note that if you have any other installation directory, then you need to replace C:\XAMPP accordingly. Rest the Folder structure …\mysql\bin\ remains the same.
  • Now type the following command on the cmd prompt:
    mysql.exe –h localhost –u root -p
  • MySQL will start and will prompt you for a password. Leave it blank and hit enter.Launch MySQL with proper parameters This should bring you the MySQL terminal.

Now write and run the SQL Query languages and do whatever you wish to. Below is a process to add shortcut to the MySQL terminal.

#3: Adding shortcut using environment variables:

We will now add a environment variable to windows so that we can open the mysql.exe terminal window anywhere from command prompt without changing the working directory. Just follow the steps below:

  • On Windows 7 / Vista:Starting Environment Variables Go to Control Panel > System > Advanced System Settings > Advance Tab > Environment Variable;
  • On Windows XP: Go to Control Panel > System > Advanced Tab > Environment Variable;
  • Now under “User Variables for ~UserName~” Click on “New” button.
  • Under “Variable Name” type: mysql
  • Under “Variable Value” type: C:\xampp\mysql\bin\mysql.exe
  • Obviously you need to change the location of …/xampp if you have any other installation directory.
  • Now Save everythingsetting the environment variables and close the window.

You are done with creating the shortcuts… To launch MySQL all you need to is:

  • Open up Command Prompt;
  • Type:
    %mysql% –h localhost –u root -p

    and hit enter (As shown on the first image). Give blank password as before and you are set to go…

Now you have got your MySQL terminal window on your Win7/XP/Vista. Use it the way you want.


I hope the article was informative and useful for you. Please do give your feedback on this. Also if you know any better method of opening MySQL terminal in Windows, then do share it with us!

Comments Feed

TOP

23 Responses

Comment Now

  1. Thanks very much man :)

  2. Thanks a lot I have been wondering about this for month and finally got it working.

  3. hi guys i was just wondering what you think the best practical practices are for learning php once you have the basics under the belt ..arrays functions loops etc…

    please help me

  4. thanks,,,iam alfien from indonesia.
    iam have 1 problem
    iam cannot open my radio….server required please disable internetsharing/nat/firewall/ispcache
    ineed tips and trik how…ican deep this problem….one more thank…man

  5. Pirzada Jeelani says:

    Hi, it worked .. thanks for the post.

  6. Soumyadeep says:

    It’s an amzing work.thanx a lot for the post.

  7. Thanks for that trying to learn mysql, this makes it so much easier.

  8. really nice

  9. thanks! especially step #3 is super useful to know :-)

  10. hey there is a problem in Step 2.
    There is an issue with the password.
    It gives an error:-
    ERROR 2003 : Can’t connect to MySQL server on ‘localhost’

  11. mia ramos says:

    Thanks very much! this tutorial helped me a lot really. Keep up the good work. Site bookmarked!

  12. thx, it works great !

  13. Excellent post !!!!!!!!!!.
    I have been looking for this since 1 montha and finally i got it.
    thanks for it.

  14. ruelramos says:

    thanks buddy…

  15. Thanks a bunch! It was driving me crazy that I clicked mysql.exe from the bin directory, but couldn’t do anything.

    Then I did a “show databases” command and realized that I didn’t have root permissions going in that way. Couldn’t figure out how to get root permissions from that window (I think it can’t be done) and your method showed me how to get a command line window that I can work from.

    Thanks again!
    Dave

  16. Hi Swashata,currently i am using Xampp on Windows 7 and I want to connect Mysql trough Command prompt,I tried the way you mentioned earlier but it doesn’t worked for me.Product version is 1.6.0.1 same file version too.Could you please help?

  17. yusuf yusliandi says:

    Saya menginstal paket XAMPP versi 1.7.3, setelah penginstalan appser nya bisa tampil di browser tetapi editor phpmyadmin tidak bisa koneksi ke server mysql .saya mendapat trouble pada editor phpmyadmin yang tdk bisa koneksi ke mysql server, adapun pesan nya sbt:
    “phpmyadmin telah berusaha membuka koneksi ke server Mysql tetapi koneksi ditolak oleh server.silahkan periksa kembali nama host, nama host, nama pengguna dan kata sandi pada file config.inc.php untuk memastikan kecocokankan nya dengan informasi yang telah diberikan oleh administrator server MYSQL” mohon unruk diberikan cara solusi penanggulangan nya. sekian dan terimakasih

  18. Thanks………really nice post….

  19. -u = user
    -p = password

    can explain -h????

    thx

  20. Ur face looks like a pice of shit but your work is really useful. Thanks man!

  21. Wawwww….you rock man!!!! your stuff are awesome!!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv badge

Trackbacks/Pingbacks

Ping Now

  1. Active Record & SQL | Five AM Software - [...] http://www.intechgrity.com/how-to-connect-to-xamppmysql-using/ [...]
  2. DECIMAL datatype of MySQL& Difference b/w DECIMAL & FLOAT | InTechgrity - [...] and score columns are the DECIMAL of 2 and 1 precision respectively. We execute the following SQL command from ...
  3. Problogger - Cara install wordpress di komputer lokal... I found your entry interesting thus I've added a Trackback to it on my weblog ...
  4. Cara Install dan Membuat Server Di Komputer Lokal - [...] Dalam tulisan selanjutnya kita akan membahas bagaimana cara install wordpress di komputer lokal.Membuat server di komputer lokal bisa dilakukan ...