MySQL在Windows下的免安装配置
1、软件的下载 到mysql的官方网站下载MySQL的解压包,mysql-noinstall-5.0.22-win32.zip
然后解压到C:\mysql里面就是MySQL数据库的全部内容。
2、配置
首先我们来看MySQL的根目录,里面有多个文件名如my-****.ini形式的文件,这就是MySQL配置
的样例文件,你可以选取其中一个,将其名字改为my.ini,MySQL启动的时候就是读取这个my.ini文
件来决定数据库的各项参数。
在my.ini文件中需要进行配置的主要是两个方面,一个是客户端,一个是服务器端。
* 客户端配置
# CLIENT SECTION #-----------------------------------------------------
port = 3306
default-character-set = gbk
需要配置的主要是两项,一个是客户端端口,一个是默认的字符集(gbk就是设置成了中文),这
里端口选用默认的3306,字符集可以根据需要修改为UTF-8或GBK。
- 服务器端配置
#SERVER SECTION #-----------------------------------------------------
port = 3306
basedir = "C:/mysql-5.0.51b-win32"
datadir = "C:/mysql-5.0.51b-win32/Data"
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\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奠定一个良好的基础。
现用my.ini
根据my-huge.ini改
Example MySQL config file for very large systems.
This is for a large system with memory of 1G-2G where the system runs mainly
MySQL.
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 /usr/local/var) 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
#password = your_password port = 3306 socket = /tmp/mysql.sock
Here follows entries for some specific programs
The MySQL server
port = 3306 socket = /tmp/mysql.sock skip-locking key_buffer = 384M max_allowed_packet = 1M table_cache = 512 sort_buffer_size = 2M read_buffer_size = 2M read_rnd_buffer_size = 8M myisam_sort_buffer_size = 64M thread_cache_size = 8 query_cache_size = 32M
Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8 basedir= C:\mysql #bind-address=127.0.0.1 datadir= C:\mysql/data #language=C:\mysql/share/english #slow query log#= #tmpdir#= #port=3306 #set-variable=key_buffer=16M
Server=C:\mysql/bin/mysqld-nt.exe user=root password=mysql
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
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=, MASTER_PORT=,
MASTER_USER=, MASTER_PASSWORD= ;
where you replace , , by quoted strings and
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 =
The username the slave will use for authentication when connecting
to the master - required
#master-user =
The password the slave will authenticate with when connecting to
the master - required
#master-password =
The port the master is listening on.
optional - defaults to 3306
#master-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 = 384M #bdb_max_lock = 100000
Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/var/ #innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend #innodb_log_group_home_dir = /usr/local/var/ #innodb_log_arch_dir = /usr/local/var/
You can set .._buffer_pool_size up to 50 - 80 %
of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 384M #innodb_additional_mem_pool_size = 20M
Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 100M #innodb_log_buffer_size = 8M #innodb_flush_log_at_trx_commit = 1 #innodb_lock_wait_timeout = 50
quick max_allowed_packet = 16M
no-auto-rehash
Remove the next comment character if you are not familiar with SQL
#safe-updates
key_buffer = 256M sort_buffer_size = 256M read_buffer = 2M write_buffer = 2M
key_buffer = 256M sort_buffer_size = 256M read_buffer = 2M write_buffer = 2M
interactive-timeout