Home Database Mysql Tutorial Windows下使用Cygwin编译MySQL客户端_MySQL

Windows下使用Cygwin编译MySQL客户端_MySQL

Jun 01, 2016 pm 01:04 PM
cygwin mysql windows client compile

MinTTY 是一个小巧但却很实用的 Cygwin 终端机,但有个严重的问题就是无法调用交互性的 Windows 原生程序,比如说 mysql.exe,当你在 MinTTY 中输入如下的命令:

代码如下:


$ mysql -uroot -p


本来 mysql.exe 会提示输入密码,但在 MinTTY 中程序会直接挂起,不再响应,实际上即使在 -p 参数后面跟上密码,也是一样的。

某些程序,比如 python,会提供参数 -i,使自身在终端中进入交互模式,可惜并非所有的程序都有这样的参数。

解决的办法,使用 Cygwin 版本的 MySQL 客户端,但 Cygwin 并没有提供,所以就只有自己动手编译一个!

在 http://dev.mysql.com/downloads 下载源码包并解压。

代码如下:


$ 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
$ cd mysql-5.5.0-m2


在动手编译之前,先打开 Cygwin 安装程序安装 readline,用来替代 MySQL 自带的。MySQL 源码包捆绑的 readline 在 Cygwin中编译会报错。

准备好以后,开始编译过程:

代码如下:


$ ./configure --without-server --without-readline CFLAGS=-O2 CXXFLAGS=-O2
$ make
$ make install


Cygwin 的编译速度是很慢的,和原生 *nix 系统完全没法比,所以如果不是闲到发慌,最好不要去编译“复杂”的 MySQL Server。

编译安装完 MySQL Client,打开 Windows 系统中的 MySQL Server,使用如下的命令测试一下:

代码如下:


$ mysql -h127.0.0.1 -uroot -p


为什么加上 -h127.0.0.1 呢?默认的情况下,不带 -h 参数或者使用 -h localhost,MySQL 都会使用 Unix socket file 连接服务器,即使你在命令中指定了端口也会被忽略的,所以肯定连接不上的,提示找不到 /tmp/mysql.sock。使用 IP 或者主机名后,MySQL 就会使用 TCP/IP 模式连接服务器的 3306 端口,这样就什么没问题了。

为了方便,在配置文件中强制客户端使用 TCP/IP 连接模式。

复制 mysql-5.5.0-m2/support-files 中的配置文件样板到 /etc/my.cnf,EG:

代码如下:


$ cp support-files/my-medium.cnf /etc/my.cnf


在 [client] 中加入 protocol=TCP,EG:

代码如下:


# The following options will be passed to all MySQL clients
[client]
#password   = your_password
port        = 3306
socket      = /tmp/mysql.sock
protocol    = TCP
 
## 指定客户端连接的默认编码,注意是 utf8,不是 utf-8
## 可根据需要自行修改
default-character-set = utf8


之后就可以使用 mysql -uroot -p 直接连接 Windows 中的 MySQL Server 了。

令人纠结的乱码问题

顺便提一下,MySQL 中大部分人都是使用的 UTF-8 编码,我也是。为了规避乱码,需要在 Cygwin/MinTTY 中把字符集设置为 UTF-8,不过让人极度不爽的是,这样的话,中文 Windows 的程序,就会乱码(比如 ping, tracert,nslookup….),因为中文 Windows 环境使用的是 GBK 字符集,没办法,要么换成 E 文 Windows,要么忍着。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1670
14
PHP Tutorial
1274
29
C# Tutorial
1256
24
Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

Compare and contrast MySQL and MariaDB. Compare and contrast MySQL and MariaDB. Apr 26, 2025 am 12:08 AM

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

MySQL: The Database, phpMyAdmin: The Management Interface MySQL: The Database, phpMyAdmin: The Management Interface Apr 29, 2025 am 12:44 AM

MySQL and phpMyAdmin can be effectively managed through the following steps: 1. Create and delete database: Just click in phpMyAdmin to complete. 2. Manage tables: You can create tables, modify structures, and add indexes. 3. Data operation: Supports inserting, updating, deleting data and executing SQL queries. 4. Import and export data: Supports SQL, CSV, XML and other formats. 5. Optimization and monitoring: Use the OPTIMIZETABLE command to optimize tables and use query analyzers and monitoring tools to solve performance problems.

How to handle high DPI display in C? How to handle high DPI display in C? Apr 28, 2025 pm 09:57 PM

Handling high DPI display in C can be achieved through the following steps: 1) Understand DPI and scaling, use the operating system API to obtain DPI information and adjust the graphics output; 2) Handle cross-platform compatibility, use cross-platform graphics libraries such as SDL or Qt; 3) Perform performance optimization, improve performance through cache, hardware acceleration, and dynamic adjustment of the details level; 4) Solve common problems, such as blurred text and interface elements are too small, and solve by correctly applying DPI scaling.

Steps to add and delete fields to MySQL tables Steps to add and delete fields to MySQL tables Apr 29, 2025 pm 04:15 PM

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.

How to uninstall MySQL and clean residual files How to uninstall MySQL and clean residual files Apr 29, 2025 pm 04:03 PM

To safely and thoroughly uninstall MySQL and clean all residual files, follow the following steps: 1. Stop MySQL service; 2. Uninstall MySQL packages; 3. Clean configuration files and data directories; 4. Verify that the uninstallation is thorough.

How to use MySQL functions for data processing and calculation How to use MySQL functions for data processing and calculation Apr 29, 2025 pm 04:21 PM

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

An efficient way to batch insert data in MySQL An efficient way to batch insert data in MySQL Apr 29, 2025 pm 04:18 PM

Efficient methods for batch inserting data in MySQL include: 1. Using INSERTINTO...VALUES syntax, 2. Using LOADDATAINFILE command, 3. Using transaction processing, 4. Adjust batch size, 5. Disable indexing, 6. Using INSERTIGNORE or INSERT...ONDUPLICATEKEYUPDATE, these methods can significantly improve database operation efficiency.

See all articles