step1:解压mysql包,我的路径是E:\mysql-5.5.19,就用%MySQL_HOME%表示。
step2:写my.ini文件,这个是mysql启动时的配置文件,压缩包里默认提供了几个配置模版,my-small.ini, my-medium.ini, my-large.ini, my-huge.ini, my-innodb-heavy-4G.ini。这几个模版的主要区别是和内存有关的。
如small模版就说:如果系统内存小于64M,并且mysql不常用使用,那就用这个模版,并且使用这个模版mysqld daemon守护精灵占用的资源最少。这个基本上就是做嵌入式数据库啦。
如果数据库在你的开发中应用中扮演一个比较重要的角色,那就用medium模版。medium模版即适合32M-64M内存的系统使用,又可以满足web开发使用。(是它自己说的,看来这个是全能型选手)
large模版,如果你的系统内存有512M,并且主要运行mysql,那就用这个。(512M现在大家都能轻松达到吧~~)
huge模版,就是系统内存在1G-2G之间用的。
my-innodb-heavy-4G这个模版就厉害,系统4G内存,并且只使用innodb表。这个基本上就是单做数据库服务器才用的。
以下贴上我的my.ini配置:
# The following options will be passed to all MySQL clients [client] # set default character for client default-character-set=utf8 #password = your_password port = 3306 socket = /tmp/mysql.sock # Here follows entries for some specific programs # The MySQL server [mysqld] # The default character set that will be used when a new schema or table is # created and no character set is defined character-set-server=utf8 #Path to installation directory. All paths are usually resolved relative to this. basedir="E:/mysql-5.5.19/" #Path to the database root datadir="E:/mysql-5.5.19/data/" # The default storage engine that will be used when create new tables when default-storage-engine=INNODB # Set the SQL mode to strict sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" # The maximum amount of concurrent sessions the MySQL server will # allow. One of these connections will be reserved for a user with # SUPER privileges to allow the administrator to login even if the # connection limit has been reached. max_connections=50 # Query cache is used to cache SELECT results and later return them # without actual executing the same query once again. Having the query # cache enabled may result in significant speed improvements, if your # have a lot of identical queries and rarely changing tables. See the # "Qcache_lowmem_prunes" status variable to check if the current value # is high enough for your load. # Note: In case your tables change very often or if your queries are # textually different every time, the query cache may result in a # slowdown instead of a performance improvement. query_cache_size=67108864 # The number of open tables for all threads. Increasing this value # increases the number of file descriptors that mysqld requires. # Therefore you have to make sure to set the amount of open files # allowed to at least 4096 in the variable "open-files-limit" in # section [mysqld_safe] table_cache=256 # Maximum size for internal (in-memory) temporary tables. If a table # grows larger than this value, it is automatically converted to disk # based table This limitation is for a single table. There can be many # of them. tmp_table_size=9M # How many threads we should keep in a cache for reuse. When a client # disconnects, the client's threads are put in the cache if there aren't # more than thread_cache_size threads from before. This greatly reduces # the amount of thread creations needed if you have a lot of new # connections. (Normally this doesn't give a notable performance # improvement if you have a good thread implementation.) thread_cache_size=16 port = 3306 socket = /tmp/mysql.sock skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M # Replication Master Server (default) # binary logging is required for replication log-bin=mysql-bin # binary logging format - mixed recommended binlog_format=mixed # 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 # Uncomment the following if you are using InnoDB tables innodb_data_home_dir ="E:/mysql-5.5.19/data/" innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir ="E:/mysql-5.5.19/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 = 64M # Additional memory pool that is used by InnoDB to store metadata # information. If InnoDB requires more memory for this purpose it will # start to allocate it from the OS. As this is fast enough on most # recent operating systems, you normally do not need to change this # value. SHOW INNODB STATUS will display the current amount used. innodb_additional_mem_pool_size = 2M # Set .._log_file_size to 25 % of buffer pool size # Size of each log file in a log group. You should set the combined size # of log files to about 25%-100% of your buffer pool size to avoid # unneeded buffer pool flush activity on log file overwrite. However, # note that a larger logfile size will increase the time needed for the # recovery process. innodb_log_file_size = 5M # The size of the buffer InnoDB uses for buffering log data. As soon as # it is full, InnoDB will have to flush it to disk. As it is flushed # once per second anyway, it does not make sense to have it very large # (even with long transactions). innodb_log_buffer_size = 1M # If set to 1, InnoDB will flush (fsync) the transaction logs to the # disk at each commit, which offers full ACID behavior. If you are # willing to compromise this safety, and you are running small # transactions, you may set this to 0 or 2 to reduce disk I/O to the # logs. Value 0 means that the log is only written to the log file and # the log file flushed to disk approximately once per second. Value 2 # means the log is written to the log file at each commit, but the log # file is only flushed to disk approximately once per second. innodb_flush_log_at_trx_commit = 0 innodb_lock_wait_timeout = 50 # Number of threads allowed inside the InnoDB kernel. The optimal value # depends highly on the application, hardware as well as the OS # scheduler properties. A too high value may lead to thread thrashing. innodb_thread_concurrency=10 [mysqldump] quick max_allowed_packet = 16M [mysql] default-character-set=utf8 no-auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout
注意上边mysqld的字符集设置,以前版本的mysqld可以使用default-character-set=utf8,但是新版本那个参数已经删除了,必须使用character-set-server=utf8,否则日志中会记录错误:[ERROR] mysqld: unknown variable 'default-character-set=utf8'。
step3:配置文件写好之后,可以使用mysqld --defaults-file="E:\mysql-5.5.19\my.ini"命令来启动mysql。这时root账户不需要密码。基于最普通的安全考虑,你也应该给root账户设置一个密码。使用如下步骤:
use mysql; update user set password = password('root');
在这里最好使用password()函数,这样有两方面好处,一,设置的密码root是加密存储的。select * from user;时,你会看到密码是一串字符。二,这样做不用更改user表的authentication_string字段的设置。
注意这时有默认的匿名用户,如果不需要应该删掉,在user表中可以看到。
step4:设置完成密码之后,只有重启mysqld服务,更改才能生效。如果只是关闭cmd窗口显然是不起作用的,你在进程管理器中应该还能看到mysqld并没有关掉。必须另开一个cmd,使用如下语句:
mysqladmin shutdown -uroot -p
然后再次启动mysqld就ok了,再次启动的时候,并不需要加上--defaults-file这个参数,如果你没有对它做修改的话。
如有错误敬请指正,渴望真像的脚步从未停歇。