connecting to mysql from cygwin - mysql

I can successfully connect to MySQL from a DOS prompt, but when I try to connect from cygwin, it just hangs.
$/cygdrive/c/Program\ Files/MySQL/MySQL\ Server\ 5.1/bin/mysql -u root -p
What's wrong?

I just came across this, and when I read someone's mention of it being a windows/DOS command that you run in cygwin I did a which mysql and that gave me:
$ which mysql
/cygdrive/c/Program Files/MySQL/MySQL Server 5.5/bin/mysql
So I ran the cygwin Setup.exe searched for "mysql" and installed the latest "mysql client". Now which mysql looks like:
$ which mysql
/usr/bin/mysql
And the MySQL command works in cygwin :)
Though it's an old question, it would be nice to have the actual answer here, as people (like myself) might still stumble across it.
If your attempts to run the MySQL client from Cygwin return the following error:
$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2)
Then you can fix it by adding the explicit -h 127.0.0.1 options to the command line, as in:
$ mysql -u root -p -h 127.0.0.1
Updates based on comments:
To avoid specifying -h 127.0.0.1 on the command line every time you connect, you can add:
[client]
host=127.0.0.1
to the file /etc/my.cnf
On some installations of Cygwin, specifying the host with -h might not be enough. If so, try also specifying:
--protocol=tcp
or add
protocol=tcp
to the config file.

Assuming that you have a native Windows build of MySQL, there is a terminal emulation incompatibility between DOS (command prompt) windows and bash. The prompt for mysql isn't showing up.
To confirm this, type a command and return - it will probably work, but the prompt and the echo of the command (what you're typing) is getting lost.
There may be a workaround in either the CYGWIN sytem properties or in bash, but I've never taken the time to work this one out.

Other answers lack the following key detail:
Cygwin has two shells:
Default: c:\cygwin\bin\mintty.exe
Basic: c:\cygwin\Cygwin.bat (which launches c:\cygwin\bin\bash.exe)
The Win32 MySQL can write properly to #2, but not #1, because Win32 MySQL cannot probe stdin properly (thanks #PeterNore)
Want to know if you're using Win32 MySQL? Use which, e.g.
$ which mysql
/cygdrive/c/Program Files/MySQL/MySQL Server 5.1/bin/mysql
Bonus: Cygwin guide to overcoming path problems (thanks #Dustin)

I posted a solution/workaround here:
enter key sometimes not recognized in windows apps under cygwin

Run bash from the cmd.exe executable and then mysql will work inside bash.
Create a shortcut for cmd.exe on your desktop.
Open up the properties for the shortcut and change the startup directory to the cygwin bin directory (usually C:\cygwin\bin).
Add "/c bash.exe" to the end of the command in the target parameter.
This will run bash under the windows cmd.exe environment and when you attempt to run mysql it will execute as you would expect. This is working under windows 7 but has not been tested in any other version.

Put cygwin bin directory in path env variable.
Use command window by running cmd
Run bash -l in cmd window
Then MySQL can be run without problem.

Svend Hansen's answer is the right one:
Install windows mysql server files (from mysql-5.5.25-win32.msi for example)
Install Cygwin mysql client with cygwin installer (setup.exe)
Connect to your server in a cygwin window using cygwin client "mysql -u[user] -p[Password] -h[host]", in my case "mysql -uroot -pXXXX -h127.0.0.1"
I think that when the question was posted, the cygwin setup did not provide mysql components, which is solved now.

Althoug Svend Hansen answer has some points, another thing is the PATH in Environment variables - if the path to mysql is before that of cygwin
which mysql
will show
/cygdrive/c/Program Files/MySQL/MySQL Server 5.5/bin/mysql
otherwise it will show the cygwin client.
As reference Wikipedia says:
Some programs may add their directory to the front of the PATH
variable's content during installation, to speed up the search process
and/or override OS commands.

Download Cygwin
Install mysql client app
create an alias in .bashrc file
alias mysql='mysql -h 127.0.0.1'
execute source .bashrc
Now you can connect to mysql
mysql -u user -p

I have created a semi-fix for this that satisfies me.
I ran cygwin.bat in cmd.exe, then typing mysql in- everything worked fine.
I realized right there that the problem was mintty.
Easy solution? Download Console2, and under settings you can point
it to the cygwin shell. Restart Console2, run mysql and the output
appears.
This is advantageous anyways, because Console2 has a more robust interface/customization than Mintty. I really like the transparency and color mapping options.

Do This:
just copy ur mysql.exe from C:\Program Files\MySQL\MySQL Server 5.5\bin
paste this mysql.exe in C:\cygwin\usr\local\bin
now run which mysql, It will

Disclaimer: The following solved this issue for me under MinTTY on MinGW/MSYS. From research, I believe this same root cause affects Cygwin as well.
Answer is posted here: https://stackoverflow.com/a/23164362/1034436
In a nutshell, you'll need to prepend your mysql command with winpty's console.exe (or have aliases that does so). This solution worked with native Windows MySQL executables and not a special cygwin/mingw build. You do, however, have to compile winpty, but that was simple and painless, and worked as per their documentation for me.
Note: This also solved my issue with several other native Windows console applications, namely Python and Mercurial with OpenSSH.

Reinstall cygwin and during reinstallation search for mysql in packages, install the mysql client and then it would work fine.

Found this question today 2018-03-18 looking for some answers to
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2 "No such file or directory")
The file /etc/my.conf references config files in /etc/my.cnf.d
I added this to /etc/my.cnf.d/client.cnf:
[client]
host=127.0.0.1
protocol=tcp
After that I was able to access the local windows MySQL instance from a cygwin terminal using mysql -u root -p

Related

Why mysql access doesn't work on git bash?

I'm trying to access mysql using Git Bash and/or ConEmu but it doesn't work.
I'm using the command: mysql -u root -p
ConEmu : ask me to enter the password. I write it but nothing happen. (the password is also really randomly hidden with *, some char yes other not, it depends).
Git Bash : after I text mysql -u root -p doesn't make anything.
everything works with normal windows CMD.
What do I do wrong guys ?
This is likely a terminal issue arising from clashes between git bash (cygwin) and the windows command prompt. A similar question prompts a number of good answers, including:
winpty mysql
On the 8.0.29 build I have locally, the mysql command line is invoked with the slightly differently named mysqlsh.exe, and I can get it to run with
winpty mysqlsh
You can alias this command in the usual bash way.
alias mysql='winpty mysqlsh'
I am a Linux user and do not have a whole lot experience with Windows.
My assumption is that if you run Windows, then your version of mysql that you run within CMD is absolutely different from mysql that you run within Git Bash. This is why it will not run as you would expect.
If you have file command within Git Bash environment, try running file $(which mysql). In case it is a Linux version and can be run from Git Bash it will output something like this.
/usr/bin/mysql: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, fo
r GNU/Linux 3.2.0, BuildID[sha1]=25171134a33827663abd4250e4e33ea524dd3d01, stripped

MySQL Dump Not Working In MySQL

I just installed a new Windows 7 Professional machine with MySQL 5.6.22. When trying to run the mysqldump command, I get the following:
E:>mysqldump -u root -p world > world.sql
mysqldump: unknown option '--no-beep'
Mysqldump works fine on my other machines running 5.16.15 and 5.5.xx.
Unfortunately, the msi installer for MySQL 5.6.15 will not work as some packages cannot be found. Oracle, it seems, will not support previous editions of 5.6.
On top of that, the MySQL installer for 5.6.23 only installs 5.6.22 in a round about way. The MSI installer has issues.
Can anyone shed light on mysqldump not working in 5.6.22?
Thanks!
I think you need to run the mysqldump command from the path it is installed, first cd into the folder and then run the command like this
C:\MySQL\MySQL Server 5.6\bin>mysqldump -u root -p -B database>name_of_backup_file.sql
I had the same issue. Search your active my.ini for the [client] section. Likely you will find the following:
[client]
no-beep
Comment or delete no-beep. It solves the 'no-beep' issue (now I have a new annoying error, hooray!). Be carefully checking whats your active my.ini because you might have some on different places.
Edit: Now, as I can call mysqldump w/o error, option --help tells me the follwing:
Default options are read from the following files in the given order:
C:\Windows\my.ini C:\Windows\my.cnf C:\my.ini C:\my.cnf [Your Server DIR]\my.ini [Your Server DIR]\my.cnf

Cannot connect to MySQL Workbench on mac. Can't connect to MySQL server on '127.0.0.1' (61) Mac Macintosh

Cannot connect to MySQL Workbench on mac. I get the following error: Could not connect, server may not be running. Can't connect to MySQL server on '127.0.0.1' (61)
The help would be appreciated.
Thank You!
Ran into a similar issue and my problem was that MySQL installed itself configured to run on non-default port. I do not know the reason for that, but to find out which port MySQL is running on, run the following in MySql client:
SHOW GLOBAL VARIABLES LIKE 'PORT';
Go to System preferences -> MySql and check the state of your MySql instance.
There may be one or multiple reasons if you are not able to connect to MAC OS X MySQL server with MySQL-workbench.
When you press 'test connection' you might see this error. This could be explained briefly if you go step by step through 'Configure server management..'
On the basis of the red crosses you can filter out the real problem.
The most common problems are associated with the installation of MySQL-server. Few people either forget to install the server prior to installing MySQL-workbench. Some others would install a part of the product. Please check whether you have also installed all the 3 parts that comes with the MySQL-Server dmg(disk image) file which contains mysql-server package. Those 3 parts are: MySQL server, preference pane and startup item.
Note: If you haven't selected preference pane then you won't be able to start mysql server instance from the System preferences.
After you make sure that you have installed each item then you can check server instance of your native mysql-server. Open System preferences from dock and click MySQL. Then click Start MySQL Server to start the server instance. If the server instance is stopped, then MySQL-workbench won't be able to connect to the MySQL server.
If you are still facing issue, then you need to check the port of the connection which you are making. Default port is '3307' and NOT '3306'. You can check it with using the following command in mysql terminal:
SHOW GLOBAL VARIABLES LIKE 'PORT';
Please note that this process helps you to connect to the local instance. If you have to connect to a remote server, then you have to enter that specific IP and Port. Contact your server's administrator if you are facing the issue. As this question specifically states that the problem is related to connecting to the local instance, I am not writing checks that you may need to ensure.
This steps are all in the terminal:)->source
Step make sure your server is running:
sudo /usr/local/mysql/support-files/mysql.server start
Check MySQL version. "This also puts you in to a shell interactive dialogue with mySQL, type q to exit."
/usr/local/mysql/bin/mysql -v
Make your life easier: "After installation, in order to use mysql commands without typing the full path to the commands you need to add the mysql directory to your shell path, (optional step) this is done in your “.bash_profile” file in your home directory, if you don’t have that file just create it using vi or nano:"
cd ; nano .bash_profile
paste in and save:
export PATH="/usr/local/mysql/bin:$PATH"
"The first command brings you to your home directory and opens the .bash_profile file or creates a new one if it doesn’t exist, then add in the line above which adds the mysql binary path to commands that you can run. Exit the file with type “control + x” and when prompted save the change by typing “y”. Last thing to do here is to reload the shell for the above to work straight away."
source ~/.bash_profile
mysql -v
"You will get the version number again, just type “q” to exit."
Check out on which port the server is running:
in your terminal type in: mysql
and then
SHOW GLOBAL VARIABLES LIKE 'PORT';
use everytime a semikolon in the mysql client (shell)!
now you know your port and where you can configure your server(in the terminal with mysql shell/client). but for a successful connection with MySQL Benchmark or an other client you have to know more. username, passwort hostname and port. after the installation the root user has no passwort so set(howtoSetPW) the passwort in terminal with mysql shell/client. and the server is running local. so type in root, yourPW, localhost and 3007. have fun!
Try restarting the mysql or starting it if it wasn't started already. Type this within terminal.
mysql.server restart
To auto start go to the following link below:
How to auto-load MySQL on startup on OS X Yosemite / El Capitan
In my case I had a previous mySQL server installation (with non-standard port), and I re-installed to a different directory & port. Then I got the same issue (in windows). To resolve, you click on home + add new connection.
If you need to know the port of your server, you can find it when you start My SQL command line client and run command status (as below). In windows it is via All Programs -> MySQL -> MySQL ServerX.Y -> MySQL X.Y Command Line Client
I had the same issue, I solved this with the following steps:
Install the MySql (DMG) from this link
If the mysql package comes with the file name "mysql-5.7.13...." and
"MySql.prefPane" then your life is really easy.
Just click on "mysql-5.7.13...." and follow the instructions.
After the installation is done, click on "MySql.prefPane" and checkout "Only
for this user" in the popup. We use "MySql.prefPane" to start the mysql
server as this is really imp because without this you will end up having
errors.
Click on Start MySql Server in the next dialog box.
OR
If you don't see "MySql.prefPane" in the package then follow these steps:
Click on package "mysql-5.7.13...." and this will show you one password as
soon as installation is done. That password is use to start the connection.
You can change it. I will let you know in a while.
After installation save the password (this is really important - you'll need it later), open terminal.
$ cd /usr/local/mysql/bin/
$ ./mysql -u root -h localhost -p
And then type the password from above. This should start mysql>
To change the password:
$ cd /usr/local/mysql/bin/
$ ./mysqladmin -u root -p password 'new_password'
Enter Password: <type new password here>
$ ./mysql -u root -h localhost -p
... and log in with the new password.
After this you can go to MySql workbench and test connection. It should connect.
brew services start mysql defualt set --bind-address=127.0.0.1 with /usr/local/Cellar/mysql/5.6.27/homebrew.mxcl.mysql.plist,so replace --bind-address=127.0.0.1 with --bind-address=* or --bind-address=0.0.0.0
for mac : check the compatible version of mysql server in workbench>preference>MySql
if it's the same version with your mysql server in: cd /usr/local/
I am using those commands on MacOs after getting the same error
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files/mysql.server restart
I had the same problem. I removed mySQL completely, and reinstall it using homebrew.
I had same problem, but it worked for me.
check if you have mysql installed
If you don't have mysql installed, download from this link: https://dev.mysql.com/downloads/mysql/
follow this instructions to install
https://dev.mysql.com/doc/mysql-osx-excerpt/5.7/en/osx-installation-pkg.html
You can test the connection without any problem.
(Sorry for my english, I agree fix me please)
I Hope I've helped.
Greetings.
I ran into the same scenario
I opened "System Preferences", clicked "MySQL", then clicked "Initialize Database" button. I entered a new password and saved it in a safe place.
After that i restarted the MySql Instance (in the System Preferences dialog as well).
After that i opened MySqlWorkbench and opened the default connection, entered the password i set before and: Viola, i can do whatever i want :-)
I had this same issue on Monterey. Make sure you're selecting the correct download according to your processor architecture.
Community download processor architecture
Also, for the Connection Method use the Local Socket/Pipe
connection method
Dropping this to share my experience.
I had the same problem and realise I didn't start MySql server.
The steps below shows how I was able to login:
To start your server, Go to Preference and find MySql.
Click on the instance tab to start the server
Afterward, return back to Mysql Workbench to start the Local Instance and you'll be connected.
Have fun !
I had similar issues in Mac OS Catalina and the easiest way to solve it is by downloading HOMEBREW package manager for mac. Follow the steps to install HOMEBREW and mysql server.
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew install mysql
$ brew tap homebrew/services
$ brew services start mysql
mysqladmin -u root password 'yourpassword'
Now try using mySQLworkbench it should work.

How to use Sql from DOS prompt

Hi I have installed MySQL from oracle website, but did not get a "MySQL Command Line" option under MySQL in Programs menu.
So I looked up on this site how to execute sql queries from DOS command prompt.
I found an answer on this site that advised to type in something like: sql root u- p- etc. but this does not work.
Can anyone advise me the syntax to use to go into sql from DOS, or direct me to the answer described above (I cannot locate it)
I use Windows 7 and downloaded the ODBC driver, too.
Many thanks.
Unless MySQL's bin directory is in your PATH variable, you will need to either be in the directory, or write an absolute path to it to execute.
Try something like this (depending on your installation):
cd "C:\Program Files\MySQL\MySQL Server 5.5\bin"
mysql -uroot
Alternatively, you could type this directly:
"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe" -uroot
cd/
cd wamp
cd bin
cd mysql
cd mysql5.0.51b
#################################
note use your own version of mysql, mine is 5.0.51b
########################################
cd bin
mysql -h localhost -u root -p
////////////////////////////////
note -p that is if u use a password
////////////////////////////////////////
after this line of codes you have this
welcome note telling you the server version of mysql and your connection id
If you navigate to the bin directory of the program you just installed then type "mysql.exe"
Have a look at this guide if you get stuck with the commands
Determine the path of your MySQL installation, and add it to PATH environment variable.
SET PATH=%PATH%;C:\MySQL\bin
The above example assumes MySQL to be installed in C:\MySQL directory.
Once path is set, then you can directly execute
mysql -u root
Which logs into MySQL as root user. The -p flag can be used if password is required
It is required to execute SET PATH every time, hence you may make a batch file.

Command line MySQL from XAMPP in Cygwin [duplicate]

I can successfully connect to MySQL from a DOS prompt, but when I try to connect from cygwin, it just hangs.
$/cygdrive/c/Program\ Files/MySQL/MySQL\ Server\ 5.1/bin/mysql -u root -p
What's wrong?
I just came across this, and when I read someone's mention of it being a windows/DOS command that you run in cygwin I did a which mysql and that gave me:
$ which mysql
/cygdrive/c/Program Files/MySQL/MySQL Server 5.5/bin/mysql
So I ran the cygwin Setup.exe searched for "mysql" and installed the latest "mysql client". Now which mysql looks like:
$ which mysql
/usr/bin/mysql
And the MySQL command works in cygwin :)
Though it's an old question, it would be nice to have the actual answer here, as people (like myself) might still stumble across it.
If your attempts to run the MySQL client from Cygwin return the following error:
$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2)
Then you can fix it by adding the explicit -h 127.0.0.1 options to the command line, as in:
$ mysql -u root -p -h 127.0.0.1
Updates based on comments:
To avoid specifying -h 127.0.0.1 on the command line every time you connect, you can add:
[client]
host=127.0.0.1
to the file /etc/my.cnf
On some installations of Cygwin, specifying the host with -h might not be enough. If so, try also specifying:
--protocol=tcp
or add
protocol=tcp
to the config file.
Assuming that you have a native Windows build of MySQL, there is a terminal emulation incompatibility between DOS (command prompt) windows and bash. The prompt for mysql isn't showing up.
To confirm this, type a command and return - it will probably work, but the prompt and the echo of the command (what you're typing) is getting lost.
There may be a workaround in either the CYGWIN sytem properties or in bash, but I've never taken the time to work this one out.
Other answers lack the following key detail:
Cygwin has two shells:
Default: c:\cygwin\bin\mintty.exe
Basic: c:\cygwin\Cygwin.bat (which launches c:\cygwin\bin\bash.exe)
The Win32 MySQL can write properly to #2, but not #1, because Win32 MySQL cannot probe stdin properly (thanks #PeterNore)
Want to know if you're using Win32 MySQL? Use which, e.g.
$ which mysql
/cygdrive/c/Program Files/MySQL/MySQL Server 5.1/bin/mysql
Bonus: Cygwin guide to overcoming path problems (thanks #Dustin)
I posted a solution/workaround here:
enter key sometimes not recognized in windows apps under cygwin
Run bash from the cmd.exe executable and then mysql will work inside bash.
Create a shortcut for cmd.exe on your desktop.
Open up the properties for the shortcut and change the startup directory to the cygwin bin directory (usually C:\cygwin\bin).
Add "/c bash.exe" to the end of the command in the target parameter.
This will run bash under the windows cmd.exe environment and when you attempt to run mysql it will execute as you would expect. This is working under windows 7 but has not been tested in any other version.
Put cygwin bin directory in path env variable.
Use command window by running cmd
Run bash -l in cmd window
Then MySQL can be run without problem.
Svend Hansen's answer is the right one:
Install windows mysql server files (from mysql-5.5.25-win32.msi for example)
Install Cygwin mysql client with cygwin installer (setup.exe)
Connect to your server in a cygwin window using cygwin client "mysql -u[user] -p[Password] -h[host]", in my case "mysql -uroot -pXXXX -h127.0.0.1"
I think that when the question was posted, the cygwin setup did not provide mysql components, which is solved now.
Althoug Svend Hansen answer has some points, another thing is the PATH in Environment variables - if the path to mysql is before that of cygwin
which mysql
will show
/cygdrive/c/Program Files/MySQL/MySQL Server 5.5/bin/mysql
otherwise it will show the cygwin client.
As reference Wikipedia says:
Some programs may add their directory to the front of the PATH
variable's content during installation, to speed up the search process
and/or override OS commands.
Download Cygwin
Install mysql client app
create an alias in .bashrc file
alias mysql='mysql -h 127.0.0.1'
execute source .bashrc
Now you can connect to mysql
mysql -u user -p
I have created a semi-fix for this that satisfies me.
I ran cygwin.bat in cmd.exe, then typing mysql in- everything worked fine.
I realized right there that the problem was mintty.
Easy solution? Download Console2, and under settings you can point
it to the cygwin shell. Restart Console2, run mysql and the output
appears.
This is advantageous anyways, because Console2 has a more robust interface/customization than Mintty. I really like the transparency and color mapping options.
Do This:
just copy ur mysql.exe from C:\Program Files\MySQL\MySQL Server 5.5\bin
paste this mysql.exe in C:\cygwin\usr\local\bin
now run which mysql, It will
Disclaimer: The following solved this issue for me under MinTTY on MinGW/MSYS. From research, I believe this same root cause affects Cygwin as well.
Answer is posted here: https://stackoverflow.com/a/23164362/1034436
In a nutshell, you'll need to prepend your mysql command with winpty's console.exe (or have aliases that does so). This solution worked with native Windows MySQL executables and not a special cygwin/mingw build. You do, however, have to compile winpty, but that was simple and painless, and worked as per their documentation for me.
Note: This also solved my issue with several other native Windows console applications, namely Python and Mercurial with OpenSSH.
Reinstall cygwin and during reinstallation search for mysql in packages, install the mysql client and then it would work fine.
Found this question today 2018-03-18 looking for some answers to
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2 "No such file or directory")
The file /etc/my.conf references config files in /etc/my.cnf.d
I added this to /etc/my.cnf.d/client.cnf:
[client]
host=127.0.0.1
protocol=tcp
After that I was able to access the local windows MySQL instance from a cygwin terminal using mysql -u root -p