Nice programing

cygwin에서 mysql에 연결

nicepro 2020. 12. 29. 08:27
반응형

cygwin에서 mysql에 연결


DOS 프롬프트에서 MySQL에 성공적으로 연결할 수 있지만 cygwin에서 연결하려고하면 중단됩니다.

$/cygdrive/c/Program\ Files/MySQL/MySQL\ Server\ 5.1/bin/mysql -u root -p

뭐가 문제 야?


MySQL의 기본 Windows 빌드가 있다고 가정하면 DOS(명령 프롬프트) 창과 bash. 에 대한 프롬프트 mysql가 표시되지 않습니다.

이를 확인하려면 명령을 입력하고 리턴하십시오. 작동 할 수 있지만 프롬프트와 명령의 에코 (입력하는 내용)가 손실됩니다.

CYGWIN시스템 속성이나에서 해결 방법이있을 수 있지만이 문제를 해결 bash하는 데 시간을 투자 한 적이 없습니다.


나는 방금 이것을 보았고, cygwin에서 실행하는 windows / DOS 명령이라는 누군가의 언급을 읽었을 때 나는 a를 which mysql했고 그것은 나에게주었습니다.

$ which mysql
/cygdrive/c/Program Files/MySQL/MySQL Server 5.5/bin/mysql

그래서 cygwin을 실행하여 Setup.exe"mysql"을 검색하고 최신 "mysql 클라이언트"를 설치했습니다. 이제 which mysql다음과 같이 보입니다.

$ which mysql
/usr/bin/mysql

그리고 MySQL 명령은 cygwin에서 작동합니다. :)

오래된 질문이지만, 사람들이 (나와 같은) 여전히 우연히 발견 할 수 있기 때문에 여기에 실제 답변이 있으면 좋을 것입니다.

Cygwin에서 MySQL 클라이언트를 실행하려고하면 다음 오류가 반환됩니다.

$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2)

그런 다음 다음과 같이 명시 적 -h 127.0.0.1옵션을 명령 줄 에 추가하여 수정할 수 있습니다 .

$ mysql -u root -p -h 127.0.0.1

댓글에 따른 업데이트 :

-h 127.0.0.1연결할 때마다 명령 줄에 지정하지 않으려면 다음을 추가 할 수 있습니다.

[client]
host=127.0.0.1

파일에 /etc/my.cnf

Cygwin의 일부 설치에서는 호스트를 지정하는 -h것으로 충분하지 않을 수 있습니다. 그렇다면 다음을 지정해보십시오.

--protocol=tcp

또는 추가

protocol=tcp

구성 파일에.


다른 답변에는 다음과 같은 주요 세부 정보가 없습니다.

Cygwin에는 두 개의 쉘이 있습니다.

  1. 기본: c:\cygwin\bin\mintty.exe
  2. 기본 : c:\cygwin\Cygwin.bat(시작됨 c:\cygwin\bin\bash.exe)

는 Win32 MySQL이 # 2,하지만 제대로 쓸 수 없는 때문에, # 1 에서 Win32 MySQL이 제대로 stdin을 조사 할 수없는 (감사 @PeterNore)

Win32 MySQL을 사용하고 있는지 알고 싶으십니까? 사용 which예 :

$ which mysql
/cygdrive/c/Program Files/MySQL/MySQL Server 5.1/bin/mysql

보너스 : 경로 문제 극복에 대한 Cygwin 가이드 ( @Dustin에게 감사드립니다 )


여기에 솔루션 / 해결 방법을 게시했습니다.

cygwin의 Windows 앱에서 때때로 인식되지 않는 키 입력


cmd.exe 실행 파일에서 bash를 실행하면 mysql이 bash 내에서 작동합니다.

  1. 바탕 화면에 cmd.exe에 대한 바로 가기를 만듭니다.
  2. 바로 가기의 속성을 열고 시작 디렉토리를 cygwin bin 디렉토리 (일반적으로 C : \ cygwin \ bin)로 변경합니다.
  3. 대상 매개 변수의 명령 끝에 "/ c bash.exe"를 추가하십시오.

이것은 windows cmd.exe 환경에서 bash를 실행하고 mysql을 실행하려고하면 예상대로 실행됩니다. 이것은 Windows 7에서 작동하지만 다른 버전에서는 테스트되지 않았습니다.


  1. cygwin bin 디렉토리를 env 변수 경로에 넣으십시오.
  2. cmd를 실행하여 명령 창 사용
  3. cmd 창에서 bash -l 실행

그러면 MySQL을 문제없이 실행할 수 있습니다.


Svend Hansen의 대답은 옳습니다.

  • Windows mysql 서버 파일 설치 (예 : mysql-5.5.25-win32.msi)

  • cygwin 설치 프로그램 (setup.exe)을 사용하여 Cygwin mysql 클라이언트 설치

  • cygwin 클라이언트 "mysql -u [user] -p [Password] -h [host]"(제 경우에는 "mysql -uroot -pXXXX -h127.0.0.1")를 사용하여 cygwin 창에서 서버에 연결합니다.

질문이 게시되었을 때 cygwin 설정은 mysql 구성 요소를 제공하지 않았으며 현재 해결되었습니다.


나는 이것에 대해 나를 만족시키는 반 수정을 만들었습니다. cmd.exe에서 cygwin.bat를 실행 한 다음 mysql을 입력했습니다. 모든 것이 잘 작동했습니다.

나는 그 문제가 민첩하다는 것을 바로 깨달았습니다.

쉬운 해결책? Console2를 다운로드 하고 설정에서 cygwin 셸을 가리킬 수 있습니다. Console2를 다시 시작하고 mysql을 실행하면 출력이 나타납니다.

이것은 Console2가 Mintty보다 더 강력한 인터페이스 / 사용자 정의를 가지고 있기 때문에 어쨌든 유리합니다. 투명도와 색상 매핑 옵션이 정말 마음에 듭니다.


이 작업을 수행:

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

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.


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.


  1. Download Cygwin
  2. Install mysql client app

  3. create an alias in .bashrc file

    alias mysql='mysql -h 127.0.0.1'

  4. execute source .bashrc

Now you can connect to mysql

mysql -u user -p


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

ReferenceURL : https://stackoverflow.com/questions/329866/connecting-to-mysql-from-cygwin

반응형