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,要么忍着。

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
