Use Cygwin in Windows to compile MySQL client, cygwinmysql
MinTTY is a small but practical Cygwin terminal, but a serious problem is that it cannot call interactive Windows native programs, such as mysql.exe. When you enter the following command in MinTTY:
Copy codeThe Code is as follows:
$ Mysql-uroot-p
Mysql.exe will prompt you to enter the password, but in MinTTY, the program will be suspended directly and no response will be received. In fact, even if the password is followed by the-p parameter, it will be the same.
Some programs, such as python, provide parameter-I so that they can enter the interaction mode in the terminal. Unfortunately, not all programs have such parameters.
The solution is to use the MySQL client of Cygwin version, but Cygwin does not provide it, so you have to compile one by yourself!
Download the source package in the http://dev.mysql.com/downloads and unzip it.
Copy codeThe Code is as follows:
$ Wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.0-m2.tar.gz/from ......
$ Tar zxvf mysql-5.5.0-m2.tar.gz
$ Mysql-5.5.0-m2 cd
Before compiling, open the Cygwin installer to install readline to replace the built-in MySQL. The readline bound to the MySQL source code package reports an error during Cygwin compilation.
After preparation, start the compilation process:
Copy codeThe Code is as follows:
$./Configure -- without-server -- without-readline CFLAGS =-O2 CXXFLAGS =-O2
$ Make
$ Make install
The Compilation speed of Cygwin is very slow, and it cannot be compared with that of the native * nix system. If it is not idle, it is best not to compile the "complicated" MySQL Server.
After compiling and installing the MySQL Client, open MySQL Server in Windows and test it with the following command:
Copy codeThe Code is as follows:
$ Mysql-h127.0.0.1-uroot-p
Why is-h127.0.0.1 added? By default, MySQL uses Unix socket file to connect to the server without the-h Parameter or-h localhost. Even if you specify a port in the command, therefore, the connection is definitely not available. The system prompts that/tmp/mysql cannot be found. sock. After the IP address or host name is used, MySQL uses the TCP/IP mode to connect to port 3306 of the server.
In the configuration file, force the client to use the TCP/IP connection mode.
Copy the profile template in mysql-5.5.0-m2/support-files to/etc/my. cnf, EG:
Copy codeThe Code is as follows:
$ Cp support-files/my-medium.cnf/etc/my. cnf
Add protocol = TCP, EG in [client:
Copy codeThe Code is as follows:
# The following options will be passed to all MySQL clients
[Client]
# Password = your_password
Port = 3306
Socket =/tmp/mysql. sock
Protocol = TCP
# Specify the default encoding for client connection. Note that it is utf8 instead of UTF-8.
# Modifications as needed
Default-character-set = utf8
Then you can use mysql-uroot-p to directly connect to the MySQL Server in Windows.
Tangled garbled Problem
By the way, most of MySQL's people are using UTF-8 encoding, and so am I. In order to avoid garbled characters, you need to set the character set in Cygwin/MinTTY as a UTF-8, but what makes people extremely uncomfortable is that, in this case, the Chinese Windows program will be garbled (such as ping, tracert, nslookup ....), Because the Chinese Windows environment uses the GBK character set, there is no way, either change to E-Windows, or endure.