Windows从noinstall zip安装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、medium、large、huge、heavy的配置区别1234Small: System has Medium: System has at least 64MB memoryLarge: 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数据库的数据目录)。如下,
001002003004005006007008009010011012013014015016017018019020021022023024025026027028029030031032033034035036037038039040041042043044045046047048049050051052053054055056057058059060061062063064065066067068069070071072073074075076077078079080081082083084085086087088089090091092093094095096097098099100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163# 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#password = your_passwordport = 3306socket = /tmp/mysql.sock# Here follows entries for some specific programs# The MySQL serverport = 3306socket = /tmp/mysql.sock#skip-lockingkey_buffer= 16Mmax_allowed_packet= 1Mtable_cache= 64sort_buffer_size= 512Knet_buffer_length= 8Kread_buffer_size= 256Kread_rnd_buffer_size= 512Kmyisam_sort_buffer_size= 8M# set basedir to your installation pathbasedir=E:/Program Files (x86)1/mysql-5.5.27-winx64# set datadir to the location of your data directorydatadir=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 defaultskip-federated# Replication Master Server (default)# binary logging is required for replicationlog-bin=mysql-bin# required unique># defaults to 1 if master-host is not set# but will not function as a master if omittedserver-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># (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>#innodb_log_file_size = 5M#innodb_log_buffer_size = 8M#innodb_flush_log_at_trx_commit = 1#innodb_lock_wait_timeout = 50quickmax_allowed_packet= 16Mno-auto-rehash# Remove the next comment character if you are not familiar with SQL#safe-updateskey_buffer= 20Msort_buffer_size= 20Mread_buffer= 2Mwrite_buffer= 2Mkey_buffer= 20Msort_buffer_size= 20Mread_buffer= 2Mwrite_buffer= 2Minteractive-timeout 将这两处的地址换成自己的MySQL的地址,已经date目录。注意斜线的方向,使用E:/Program Files/mysql-5.5.27-winx64或者E:\\Program Files\\mysql-5.5.27-winx64。仅有这两处需要改动,其他不必改动了,除非特殊需要。
第三步,启动MySQL
要启动MySQL也很简单,打开命令提示符。输入一下两个命令
12cd/dE:\Program Files\mysql-5.5.27-winx64\bin\mysqld --console 会出现一下内容就成功了。
010203040506070809101112131415130317 20:11:05 Plugin 'FEDERATED' is disabled.130317 20:11:05 InnoDB: The InnoDB memory heap is disabled130317 20:11:05 InnoDB: Mutexes and rw_locks use Windows interlocked functions130317 20:11:05 InnoDB: Compressed tables use zlib 1.2.3130317 20:11:05 InnoDB: Initializing buffer pool,>130317 20:11:05 InnoDB: Completed initialization of buffer pool130317 20:11:05 InnoDB: highest supported file format is Barracuda.130317 20:11:06InnoDB: Waiting for the background threads to start130317 20:11:07 InnoDB: 1.1.8 started; log sequence number 14128205130317 20:11:07 Server hostname (bind-address): '0.0.0.0'; port: 3306130317 20:11:07 - '0.0.0.0' resolves to '0.0.0.0';130317 20:11:07 Server socket created on IP: '0.0.0.0'.130317 20:11:07 Event Scheduler: Loaded 0 events130317 20:11:07 mysqld: ready for connections.Version: '5.5.27-log'socket: ''port: 3306MySQL Community Server (GPL) 为了以后的方便,将里面的内容保存到startmysql.bat文件里,以后只要双击bat就可以运行mysql了。
第四步:更改MySQL密码
默认MySQL的root密码为空的,在某些地方,密码不能输入为空,所以需要更改密码。
首先先启动MySQL数据库,可以使用上面的bat启动MySQL。
然后根据下面的命令进行更改
1234mysql -u root -p #从命令行中进入mysql的客户端use mysql;#使用mysql这个数据库update user setpassword=password("root") where user="root";#对root密码进行更改FLUSH PRIVILEGES; #刷新一下权限安装到Windows service服务开机自动启动
如果需要将MySQL开机自动运行,并且以服务的形式存在,那么按照本方法进行即可。以服务的形式打开MySQL,就不用再适用上面的批处理文件了。
先停止MySQL Server的运行。以管理员方式运行命令提示符
向WINDOWS添加服务
12E:\Program Files\mysql-5.5.27-winx64\bin>mysqld --install MySQL5.5Service successfully installed. 使用mysqld 并使用参数--install MySQL5.5,说明向服务注册一个叫MySQL5.5的服务名,如果不加服务名,则使用默认的MySQL作为服务名。
注意:使用--install 参数添加的服务为开机自动启动的。如果想要使用手工启动,那么使用参数--install-manual代替。命令mysqld --install-manual添加服务,需要手工启动服务。启动MYSQL服务
第二步只是向Windows服务添加了一个MySQL5.5的服务,但是并没有启动。可以到Windows服务里启动,或者使用命令行(需要管理员权限)
123C:\> net start MySQL5.5MySQL5.5 服务正在启动 .MySQL5.5 服务已经启动成功。从服务中停止MYSQL服务
123C:\> net stop MySQL5.5MySQL5.5 服务正在停止.MySQL5.5 服务已成功停止。删除WINDOWS的MYSQL服务
12E:\Program Files\mysql-5.5.27-winx64\bin>mysqld --remove MySQL5.5Service successfully removed.
页:
[1]