目录

本篇适用于MySQL5.5版本,并已测试通过。对MySQL5.6来说,配置文件不能用。

安装MySQL作为开发的数据库,这是一个小程序员必备的。如果是开发大型的企业级程序,请选择企业级的数据库,比如Oracle、DB2,至于Microsoft的SQLServer就算了吧。

鉴于许多人在安装MySQL的时候出现许多的问题(大多使用MySQL的安装程序安装的),这里就写写MySQL的安装。

对于Windows的MySQL的安装其实很简单。个人推荐使用免安装版的MySQL,这种版本只要下来,解压缩后配置一下就可以使用了。而对那种安装包则就比较麻烦,本篇也不做介绍。因为周围有许多人的MySQL安装使用安装程序,而安装到一半,配置不会弄,MySQL数据库也弄的怪怪的。

第一步,下载MySQL的免安装版压缩包

好了,对于MySQL的免安装程序,我们先要下载一个MySQL的压缩包。下载地址:MySQL官网下载或者腾讯旋风分享下载

说明:在MySQL下载的时候,会有个让你login或sign up的按钮,不用注册了,看下方有个No thanks, just start my download.的链接。点击可直接下载,不用登录。

对于解压缩出来的MySQL,有几个配置文件样例,有my-small.ini、my-huge.ini等等,我们只要复制其中的一个,并命名为my.ini

Small: System has Medium: System has at least 64MB memory
Large: System has at least 512MB memory and the server will run mainly MySQL.
Huge: System has at least 1GB memory and the server will run mainly MySQL.
Heavy: System has at least 4GB memory and the server will run mainly MySQL.

第二步,配置MySQL

将第一步复制的配置文件my.ini打开,我们需要修改一下basedir(MySQL数据库的文件夹)和datadir(MySQL数据库的数据目录)。如下,

Example MySQL config file for medium systems.

#

This is for a system with little memory (32M – 64M) where MySQL plays

an important part, or systems up to 128M where MySQL is used together with

other programs (such as a web server)

#

You can copy this file to

/etc/my.cnf to set global options,

mysql-data-dir/my.cnf to set server-specific options (in this

installation this directory is C:\mysql\data) or

~/.my.cnf to set user-specific options.

#

In this file, you can use all long options that a program supports.

If you want to know which options a program supports, run the program

with the "–help" option.

The following options will be passed to all MySQL clients

[client]

password = your_password

port = 3306 socket = /tmp/mysql.sock

Here follows entries for some specific programs

The MySQL server

[mysqld] port = 3306 socket = /tmp/mysql.sock

skip-locking

key_buffer = 16M max_allowed_packet = 1M table_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M

set basedir to your installation path

basedir=E:/Program Files (x86)1/mysql-5.5.27-winx64

set datadir to the location of your data directory

datadir=E:/Program Files (x86)1/mysql-5.5.27-winx64/data

Don’t listen on a TCP/IP port at all. This can be a security enhancement,

if all processes that need to connect to mysqld run on the same host.

All interaction with mysqld must be made via Unix sockets or named pipes.

Note that using this option without enabling named pipes on Windows

(via the "enable-named-pipe" option) will render mysqld useless!

#

skip-networking

Disable Federated by default

skip-federated

Replication Master Server (default)

binary logging is required for replication

log-bin=mysql-bin

required unique id between 1 and 2^32 – 1

defaults to 1 if master-host is not set

but will not function as a master if omitted

server-id = 1

Replication Slave (comment out master section to use this)

#

To configure this host as a replication slave, you can choose between

two methods :

#

1) Use the CHANGE MASTER TO command (fully described in our manual) –

the syntax is:

#

CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,

MASTER_USER=<user>, MASTER_PASSWORD=<password> ;

#

where you replace <host>, <user>, <password> by quoted strings and

<port> by the master’s port number (3306 by default).

#

Example:

#

CHANGE MASTER TO MASTER_HOST=’125.564.12.1′, MASTER_PORT=3306,

MASTER_USER=’joe’, MASTER_PASSWORD=’secret’;

#

OR

#

2) Set the variables below. However, in case you choose this method, then

start replication for the first time (even unsuccessfully, for example

if you mistyped the password in master-password and the slave fails to

connect), the slave will create a master.info file, and any later

change in this file to the variables’ values below will be ignored and

overridden by the content of the master.info file, unless you shutdown

the slave server, delete master.info and restart the slaver server.

For that reason, you may want to leave the lines below untouched

(commented) and instead use CHANGE MASTER TO (see above)

#

required unique id between 2 and 2^32 – 1

(and different from the master)

defaults to 2 if master-host is set

but will not function as a slave if omitted

server-id = 2

#

The replication master for this slave – required

master-host = <hostname>

#

The username the slave will use for authentication when connecting

to the master – required

master-user = <username>

#

The password the slave will authenticate with when connecting to

the master – required

master-password = <password>

#

The port the master is listening on.

optional – defaults to 3306

master-port = <port>

#

binary logging – not required for slaves, but recommended

log-bin=mysql-bin

Point the following paths to different dedicated disks

tmpdir = /tmp/

log-update = /path-to-dedicated-directory/hostname

Uncomment the following if you are using BDB tables

bdb_cache_size = 4M

bdb_max_lock = 10000

Uncomment the following if you are using InnoDB tables

innodb_data_home_dir = C:\mysql\data/

innodb_data_file_path = ibdata1:10M:autoextend

innodb_log_group_home_dir = C:\mysql\data/

innodb_log_arch_dir = C:\mysql\data/

You can set .._buffer_pool_size up to 50 – 80 %

of RAM but beware of setting memory usage too high

innodb_buffer_pool_size = 16M

innodb_additional_mem_pool_size = 2M

Set .._log_file_size to 25 % of buffer pool size

innodb_log_file_size = 5M

innodb_log_buffer_size = 8M

innodb_flush_log_at_trx_commit = 1

innodb_lock_wait_timeout = 50

[mysqldump] quick max_allowed_packet = 16M

[mysql] no-auto-rehash

Remove the next comment character if you are not familiar with SQL

safe-updates

[isamchk] key_buffer = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M

[myisamchk] key_buffer = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M

[mysqlhotcopy] interactive-timeout

将这两处的地址换成自己的MySQL的地址,已经date目录。注意斜线的方向,使用E:/Program Files/mysql-5.5.27-winx64或者E:\Program Files\mysql-5.5.27-winx64。仅有这两处需要改动,其他不必改动了,除非特殊需要。

第三步,启动MySQL

要启动MySQL也很简单,打开命令提示符。输入一下两个命令

cd /d E:\Program Files\mysql-5.5.27-winx64\bin\
mysqld --console

友情提醒:为了以后的方便,将里面的内容保存到startmysql.bat文件里,以后只要双击bat就可以运行mysql了。

会出现以下内容就成功了。

130317 20:11:05 [Note] Plugin 'FEDERATED' is disabled.
130317 20:11:05 InnoDB: The InnoDB memory heap is disabled
130317 20:11:05 InnoDB: Mutexes and rw_locks use Windows interlocked functions
130317 20:11:05 InnoDB: Compressed tables use zlib 1.2.3
130317 20:11:05 InnoDB: Initializing buffer pool, size = 128.0M
130317 20:11:05 InnoDB: Completed initialization of buffer pool
130317 20:11:05 InnoDB: highest supported file format is Barracuda.
130317 20:11:06  InnoDB: Waiting for the background threads to start
130317 20:11:07 InnoDB: 1.1.8 started; log sequence number 14128205
130317 20:11:07 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
130317 20:11:07 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
130317 20:11:07 [Note] Server socket created on IP: '0.0.0.0'.
130317 20:11:07 [Note] Event Scheduler: Loaded 0 events
130317 20:11:07 [Note] mysqld: ready for connections.
Version: '5.5.27-log'  socket: ''  port: 3306  MySQL Community Server (GPL)

第四步:更改MySQL密码

默认MySQL的root密码为空的,在某些地方,密码不能输入为空,所以需要更改密码。

首先先启动MySQL数据库,可以使用上面的bat启动MySQL。

然后根据下面的命令进行更改

mysql -u root -p #从命令行中进入mysql的客户端
use mysql;  #使用mysql这个数据库
update user set password=password("root") where user="root"; #对root密码进行更改
FLUSH PRIVILEGES; #刷新一下权限

安装到Windows service服务开机自动启动

如果需要将MySQL开机自动运行,并且以服务的形式存在,那么按照本方法进行即可。以服务的形式打开MySQL,就不用再适用上面的批处理文件了。

先停止MySQL Server的运行。以管理员方式运行命令提示符

向Windows添加服务

E:\Program Files\mysql-5.5.27-winx64\bin>mysqld --install MySQL5.5
Service successfully installed.

使用mysqld 并使用参数--install MySQL5.5,说明向服务注册一个叫MySQL5.5的服务名,如果不加服务名,则使用默认的MySQL作为服务名。

注意:使用--install 参数添加的服务为开机自动启动的。如果想要使用手工启动,那么使用参数--install-manual代替。命令mysqld --install-manual添加服务,需要手工启动服务。

启动MySQL服务

第二步只是向Windows服务添加了一个MySQL5.5的服务,但是并没有启动。可以到Windows服务里启动,或者使用命令行(需要管理员权限)

C:\> net start MySQL5.5
MySQL5.5 服务正在启动 .
MySQL5.5 服务已经启动成功。

从服务中停止MySQL服务

C:\> net stop MySQL5.5
MySQL5.5 服务正在停止.
MySQL5.5 服务已成功停止。

删除Windows的MySQL服务

E:\Program Files\mysql-5.5.27-winx64\bin>mysqld --remove MySQL5.5
Service successfully removed.

参考文章:Installing MySQL on Microsoft Windows Using a noinstall Zip Archive

声明:未经允许禁止转载 东东东 陈煜东的博客 文章,谢谢。如经授权,转载请注明: 转载自东东东 陈煜东的博客

本文链接地址: Windows从noinstall zip安装MySQL免安装版 – https://www.chenyudong.com/archives/installing-mysql-on-microsoft-windows-using-a-noinstall-zip-archive.html