MySQL (XAMPP) with MINGW64 on Windows - mysql

I use XAMPP for Windows, and I also use Git for windows.
I love the Git Bash console (I think Git comes with MINGW64)
But, when I need to access mysql functions from my XAMPP setup, I have to use the console that opens from XAMPP Control Panel, which is not as good as a linux-like console, like MINGW64.
Is there a way to run MySQL commands in Windows through this MINGW64 console?
Example of what I want to do in the linux-like console:
mysql my_database > file.txt <<EOF
select * (complicate statement with multiple lines)
EOF

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

Trying to edit the my.cnf file in mysql and it does not work

I'm attempting to use cat /etc/my.cnf in mysql but when I do this, it just shows -> wanting me to keep putting in inputs.
However, when I put a semicolon at the end.
cat /etc/my.cnf;
it throws an error.
How can I edit the /etc/my.cnf file?
I'm running this on terminal on a Mac and I got into the mysql server by using the command
sudo /usr/local/mysql/bin/mysql -u root
.
Are you typing this in to the mysql> shell? If so, UNIX-shell commands like cat won't do anything useful. These aren't commands MySQL knows how to deal with.
You need to run these in a plain Terminal (shell) window outside of MySQL.
By default most systems launch the bash shell which has access to command-line tools like vi, etc. The MySQL shell is SQL only.
It seems you are trying to edit MySQL configuration from MySQL shell but that will not work. Follow below
steps to edit the file
Open terminal and type below command to open mysql config file in textedit
sudo nano /etc/my.cnf
Save the file and restart MySQL
Hope this helps you

Transform a Linux command to windows (mysql)

I am doing a tutorial to install and use a database almost all the commands are in mysql command line, but one of steps is using a Linux command. The problem is that i am in windows 7 is there any way of running this command zcat ptwiki-latest-category.sql.gz | mysql wikipedia -u wikipedia --password=saskia but in windows. I am using MySQL server 5.1.32.
Thanks
You don't have zcat command in windows shell. Pipe is working on both windows and linux, so you only need zcat. It can be found in GNU utils collection for windows, for example MSYS Projects. Look at http://www.mingw.org/ after default installation you will get zcat in c:\MinGW\msys\1.0\bin\
You can log into mysql,
mysql wikipedia -u wikipedia --password=saskia
and then open your SQL file, ptwiki-latest-category.sql.gz, and paste the queries there into your command line to run them. Or you can unzip the file and run
source ptwiki-latest-category.sql
at the mysql prompt if the commands are too big.

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

connecting to mysql from cygwin

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