codename::boilingbit www.boilingbit.com/blog

12二/120

Windows下编译MySQL服务器

参考 http://dev.mysql.com/doc/refman/5.1/zh/installing.html#windows-source-build

现在最新的版本是MySQL Community Server 5.5.20,不过很多主机提供的都是5.1版本,所以我们就用5.1.61版本

http://www.mysql.com/downloads/mysql/5.1.html#downloads

下载
mysql-5.1.61.tar.gz
解压到
E:\Softwares\mysql-5.1.61

参考目录里的 INSTALL-WIN-SOURCE 文件,运行vc的cmd,然后
> cd E:\Softwares\mysql-5.1.61
> win\configure.js WITH_INNOBASE_STORAGE_ENGINE
WITH_INNOBASE_STORAGE_ENGINE 是为了支持InnoDB

> cmake .
(先关闭360杀毒,否则还会有误报)
> devenv MySql.sln /build "Release|Win32"
有8个项目没成功,是因为找不到bison.exe,简单的方法是直接用我们前面编译php用到的辅助工具:
set PATH=E:\Softwares\php-sdk\bin;%PATH%
然后再编译,显示 sql_locale.cc 有错误,解决方法是:
把 E:\Softwares\mysql-5.1.61\sql\sql_locale.cc 用notepad++(或者其他有字符集转换功能的编辑器)打开,转换成 utf-8 with BOM,但注意,网上提到的很多方法是不对的,应该这样:
转换之前必须先 格式->编码字符集->西欧语系->Windows 1252,否则因为我们用的简体中文系统,会当成字符集936到utf-8的转换。
然后编译,会有很多警告,不过不要紧,编译成功。

可选测试一下 (不过时间会非常长,不测也可以)
set PATH=E:\Softwares\Tools;E:\Softwares\strawberry-perl-5.12.3.0-portable\perl\bin;%PATH%
cd mysql-test
set MTR_VS_CONFIG=release
perl mysql-test-run.pl --force --timer
perl mysql-test-run.pl --force --timer --ps-protocol

然后比如要安装到 E:\Softwares\mysql
mkdir E:\Softwares\mysql
mkdir E:\Softwares\mysql\bin
mkdir E:\Softwares\mysql\data
mkdir E:\Softwares\mysql\share
mkdir E:\Softwares\mysql\scripts
如果要编译其他要链接到MySQL的客户端程序,还需要创建下面这些目录:
mkdir E:\Softwares\mysql\include
mkdir E:\Softwares\mysql\lib
mkdir E:\Softwares\mysql\lib\debug
mkdir E:\Softwares\mysql\lib\opt

然后复制文件:
cd E:\Softwares\mysql-5.1.61
copy client\Release\*.exe E:\Softwares\mysql\bin
copy sql\Release\mysqld.exe E:\Softwares\mysql\bin\mysqld.exe
xcopy scripts\*.* E:\Softwares\mysql\scripts /E
xcopy sql\share\*.* E:\Softwares\mysql\share /E
如果要编译其他要链接到MySQL的客户端程序,还需要复制下面这些文件:
copy libmysql\Debug\mysqlclient.lib E:\Softwares\mysql\lib\debug
copy libmysql\Debug\libmysql.* E:\Softwares\mysql\lib\debug
copy zlib\Debug\zlib.* E:\Softwares\mysql\lib\debug
copy libmysql\Release\mysqlclient.lib E:\Softwares\mysql\lib\opt
copy libmysql\Release\libmysql.* E:\Softwares\mysql\lib\opt
copy zlib\Release\zlib.* E:\Softwares\mysql\lib\opt
copy include\*.h E:\Softwares\mysql\include
copy libmysql\libmysql.def E:\Softwares\mysql\include

debug是debug版本,opt是release版本,如果前面没有编译过debug版本,可以忽略debug的这些。

然后把 E:\Softwares\mysql-5.1.61\win\data 复制到 E:\Softwares\mysql\

把 E:\Softwares\mysql-5.1.61\support-files\my-large.ini
复制为 E:\Softwares\mysql\my.ini

运行server:
cd E:\Softwares\mysql
bin\mysqld --console

第一次运行有很多警告信息:
-------------------------------------------------------------------------
120114 23:09:50 [Warning] '--skip-locking' is deprecated and will be removed in
a future release. Please use '--skip-external-locking' instead.
120114 23:09:51 InnoDB: Initializing buffer pool, size = 8.0M
120114 23:09:51 InnoDB: Completed initialization of buffer pool
InnoDB: The first specified data file .\ibdata1 did not exist:
InnoDB: a new database to be created!
120114 23:09:51 InnoDB: Setting file .\ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
120114 23:09:51 InnoDB: Log file .\ib_logfile0 did not exist: new to be created

InnoDB: Setting log file .\ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
120114 23:09:51 InnoDB: Log file .\ib_logfile1 did not exist: new to be created

InnoDB: Setting log file .\ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
120114 23:09:51 InnoDB: Started; log sequence number 0 0
120114 23:09:51 [Note] Event Scheduler: Loaded 0 events
120114 23:09:51 [Note] bin\mysqld.exe: ready for connections.
Version: '5.1.61-log' socket: '' port: 3306 Source distribution
-------------------------------------------------------------------------

主要是说创建了数据文件,按 ctrl-c 退出

先看看帮助:
bin\mysqld --verbose --help > help.txt
可以看到
--skip-locking Deprecated option, use --skip-external-locking instead.
也就是前面警告信息中的第一条
修改my.ini,把 [mysqld] 下的
skip-locking
改成
skip-external-locking

再次运行
-------------------------------------------------------------------------
120114 23:12:16 InnoDB: Initializing buffer pool, size = 8.0M
120114 23:12:16 InnoDB: Completed initialization of buffer pool
120114 23:12:16 InnoDB: Started; log sequence number 0 44233
120114 23:12:16 [Note] Event Scheduler: Loaded 0 events
120114 23:12:16 [Note] bin\mysqld: ready for connections.
Version: '5.1.61-log' socket: '' port: 3306 Source distribution
-------------------------------------------------------------------------

没有警告信息了

打开另一个cmd,运行 bin\mysqladmin -u root shutdown
也可以关闭服务器,注意,这个时候数据库的root用户还没有设置密码

如果启动server是不用--console参数,错误信息会输出到 E:\Softwares\mysql\data 下面的*.err文件中,
平时一般可以用 bin\mysqld --standalone 启动server。

启动server后可以执行一些测试,比如
bin\mysqlshow
bin\mysqlshow -u root mysql
bin\mysqladmin version status proc

现在执行一些安全措施,
删除匿名用户:
bin\mysql -u root
mysql> DELETE FROM mysql.user WHERE User = '';
mysql> FLUSH PRIVILEGES;
为root用户设置密码:
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'%' = PASSWORD('newpwd');
用你的密码替代上面的newpwd

文档是这么说的,不过我执行的时候,第二个执行错误,说找不到用户,只能

mysql> select host,user,password from mysql.user;
看一下,改用比如
mysql> SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('newpwd');
可以成功。

然后操作就需要输入密码了,比如关闭服务器时,
mysqladmin -u root -p shutdown
会提示输入密码...

好了,mysql安装完成!

但现在,php里还无法使用MySQL数据库,可以从phpinfo信息里看出来。
在另一篇文章里,我们将继续讨论这个问题。

 

© 2012, codename::boilingbit. 版权所有. 署名-非商业性使用-相同方式共享 (by-nc-sa)

by 标签: 发表评论
评论 (0) 引用 (1)

Leave a comment

(required)

:alien: :angel: :angry: :blink: :blush: :cheerful: :cool: :cwy: :devil: :dizzy: :ermm: :face: :getlost: :biggrin: :happy: :heart: :kissing: :lol: :ninja: :pinch: :pouty: :sad: :shocked: :sick: :sideways: :silly: :sleeping: :smile: :tongue: :unsure: :w00t: :wassat: :whistle: :wink: :wub: