1.下载mysql:mysql-noinstall 版本
2.加压缩导任何一个目录,最好目录名称不要有空格;
例如:D:\usr\mysql-5.0.22-win32
3,在mysql-5.0.22-win32
目录下新建一个my.ini,拷贝my-small.ini代码至my.ini;修改后如下:
1# Example MySQL config file for small systems.
2#
3# This is for a system with little memory (<= 64M) where MySQL is only used
4# from time to time and it’s important that the mysqld daemon
5# doesn’t use much resources.
6#
7# You can copy this file to
8# /etc/my.cnf to set global options,
9# mysql-data-dir/my.cnf to set server-specific options (in this
10# installation this directory is /usr/local/var) or
11# ~/.my.cnf to set user-specific options.
12#
13# In this file, you can use all long options that a program supports.
14# If you want to know which options a program supports, run the program
15# with the "–help" option.
16
17# The following options will be passed to all MySQL clients
18[client]
19#password = your_password
20port = 3306
21socket = /tmp/mysql.sock
22#这里是我们增加的内容
23#设置客户端字符集
24default-character-set=gbk
25# Here follows entries for some specific programs
26
27# The MySQL server
28[mysqld]
29port = 3306
30socket = /tmp/mysql.sock
31skip-locking
32key_buffer = 16K
33max_allowed_packet = 1M
34table_cache = 4
35sort_buffer_size = 64K
36read_buffer_size = 256K
37read_rnd_buffer_size = 256K
38net_buffer_length = 2K
39thread_stack = 64K
40#这里是我们修改的内容
41basedir=D:\DevelopTools\mysql-5.0.22-win32
42# 设置mysql数据库的数据的存放目录,必须是data,或者是\\xxx\data
43datadir=D:\DevelopTools\mysql-5.0.22-win32\data
44# 设置mysql服务器的字符集
45default-character-set=utf8
46
47# Don’t listen on a TCP/IP port at all. This can be a security enhancement,
48# if all processes that need to connect to mysqld run on the same host.
49# All interaction with mysqld must be made via Unix sockets or named pipes.
50# Note that using this option without enabling named pipes on Windows
51# (using the "enable-named-pipe" option) will render mysqld useless!
52#
53#skip-networking
54server-id = 1
55
56# Uncomment the following if you want to log updates
57#log-bin=mysql-bin
58
59# Uncomment the following if you are NOT using BDB tables
60#skip-bdb
61
62# Uncomment the following if you are using InnoDB tables
63#innodb_data_home_dir = /usr/local/var/
64#innodb_data_file_path = ibdata1:10M:autoextend
65#innodb_log_group_home_dir = /usr/local/var/
66#innodb_log_arch_dir = /usr/local/var/
67# You can set .._buffer_pool_size up to 50 – 80 %
68# of RAM but beware of setting memory usage too high
69#innodb_buffer_pool_size = 16M
70#innodb_additional_mem_pool_size = 2M
71# Set .._log_file_size to 25 % of buffer pool size
72#innodb_log_file_size = 5M
73#innodb_log_buffer_size = 8M
74#innodb_flush_log_at_trx_commit = 1
75#innodb_lock_wait_timeout = 50
76
77[mysqldump]
78quick
79max_allowed_packet = 16M
80
81[mysql]
82no-auto-rehash
83# Remove the next comment character if you are not familiar with SQL
84#safe-updates
85
86[isamchk]
87key_buffer = 8M
88sort_buffer_size = 8M
89
90[myisamchk]
91key_buffer = 8M
92sort_buffer_size = 8M
93
94[mysqlhotcopy]
95interactive-timeout
96
4,然后编写启动脚本;
1@echo off
2echo start mysql5 on localhost
3mysqld –install mysql5 –defaults-file=D:\DevelopTools\mysql-5.0.22-win32\my.ini
4net start mysql5
5pause
6
7
8
9
停止脚本
1@echo off
2echo stop mysql5
3
4net stop mysql5
5mysqld –remove mysql5
6
7pause
方法二
1、软件的下载
到mysql的官方网站下载MySQL的解压包,如mysql-noinstall-5.0.51b-win32.zip
然后将其解压到你希望数据库所在的某个位置,如C:\
这样在C:盘下面就有了C:\mysql-5.0.51b-win32这样的一个目录,里面就是MySQL数据库的全部
内容。
2、配置
首先我们来看MySQL的根目录,里面有多个文件名如my-****.ini形式的文件,这就是MySQL配置
的样例文件,你可以选取其中一个,将其名字改为my.ini,MySQL启动的时候就是读取这个my.ini文
件来决定数据库的各项参数。
在my.ini文件中需要进行配置的主要是两个方面,一个是客户端,一个是服务器端。
* 客户端配置
# CLIENT SECTION
#—————————————————–
[client]
port = 3306
[mysql]
default-character-set = gbk
需要配置的主要是两项,一个是客户端端口,一个是默认的字符集(gbk就是设置成了中文),这
里端口选用默认的3306,字符集可以根据需要修改为UTF-8或GBK。
* 服务器端配置
#SERVER SECTION
#—————————————————–
[mysqld]
port = 3306
basedir= "C:/mysql-5.0.51b-win32"
datadir= "C:/mysql-5.0.51b-win32/Data"
Server="c:/mysql-5.0.51b-win32/bin/mysqld-nt.exe"
default-character-set = gbk
default-storage-engine = INNODB
max_connections = 100
max_allowed_packet = 16M
这里主要的是端口port,数据库安装目录(也就是我们解压的目录)basedir,数据库中数据
的存储路径(也就是你将来建立的Database和Table存放的位置)datadir。
其次就是字符集的设置,最大连接数的设置等,实际的设置项要根据开发与使用的需要,参
考解压目录中的几个样例文件进行取舍配置。
3、启动Mysql数据库
* 可以在Windows环境变量的path中先加入C:\mysql-5.0.51b-win32\bin这项,这样我们就可以
在命令行中直接使用mysql的各项命令了
* 进入命令行窗口,运行c:\mysqld-nt,这是查看Windows任务管理器,发现进程中多出来一个
mysqld-nt.exe,这说明数据库已经成功的启动的了。
* 此外,我们可以把数据库注册成一个服务,随着系统的启动而启动,具体命令如下:
c:\mysqld-nt -install
运行上面的命令后,就会在系统服务中注册了一个名字为MySQL,启动来性为Automatic的服务
,这个服务默认情况下是自动启动的。
可以通过命令行的防止停止或启动,如:
c:\net start MySQL启动)
c:\net stop MySQL(停止)
c:\mysqld-nt –remove MySQL(卸载服务)
4、使用MySQL数据库
* 由于我们在环境变量的path中加入了MySQL安装目录下的bin这项,所以可以直接使用MySQL命
令。
* 配置好上面信息并启动MySQL以后,默认的用户名root,密码为空,所以我们可以使用一下命
令登陆数据库:
c:\mysql -uroot -hlocalhost
回车以后会看到如下命令行状态:
mysql>
这说明已经成功登陆了MySQL数据库。
如果想为root用户加上密码,可以退出数据库mysql>quit,然后使用如下命令设置root用户的
密码:
c:\mysqladmin -uroot password 123456
这样就将root用户的密码修改为123456了,再次登陆数据库是就要用如下代码:
c:\mysql -uroot -p123456 -hlocalhost
至此,MySQL5数据库的配置就完成了,可以通过客户端或是程序来使用这个数据库了。
5、总结
MySQL提供了Install和NotInstall两种文件包的下载和安装方式,Install方式使用起来更为直
观和方便,而notInstall方式则能让你更加的了解MySQL数据库基本配置内容,所以各有利弊。从个
人角度来看,还是比较推荐notIntall的方式来使用Mhysql数据库,这样可以为在不同的平台下使用
MySQL奠定一个良好的基础。