您的位置:首页 > 数据库 > MySQL

安装mysql

2015-09-13 12:14 926 查看
1、下载mysql-5.6.10-winx64.zip(官网没有64位msi安装文件,否则不用手动配置这么麻烦);

2、 解压至某一目录,比如D:\code\mysql-5.6.10-winx64,这是MySQL的程序目录;

3、将D:\code\mysql-5.6.10-winx64\bin添加到path环境变量;

4、新建一目录,作为MySQL数据目录,如D:\code\mysql_data,将D:\code\mysql-5.6.10-winx64\data复制到D:\code\mysql_data\data,这里面有MySQL自带的数据库和一些日志文件;

5、将D:\code\mysql-5.6.10-winx64里的my-default.ini配置文件移到D:\code\mysql_data,重命名为my.ini,当然也可以不这样组织目录结构,系统搜索my.ini选项文件的顺序可以参看http://dev.mysql.com/doc/refman/5.1/en/option-files.html

6、编写my.ini文件,比如我的:

[html] view
plaincopy

[WinMySQLAdmin]   

Server=D:/code/mysql-5.6.10-winx64/bin/mysqld.exe  

  

[client]  

no-beep  

  

# pipe  

# socket=mysql  

port=3306  

  

[mysql]  

  

default-character-set=utf8  

  

# For advice on how to change settings please see  

# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html  

# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the  

# *** default location during install, and will be replaced if you  

# *** upgrade to a newer version of MySQL.  

  

[mysqld]  

  

explicit_defaults_for_timestamp = TRUE  

  

# Remove leading # and set to the amount of RAM for the most important data  

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.  

innodb_buffer_pool_size = 2G  

  

# Remove leading # to turn on a very important data integrity option: logging  

# changes to the binary log between backups.  

# log_bin  

  

# These are commonly set, remove the # and set as required.  

  

basedir="D:\code\mysql-5.6.10-winx64\"  

datadir="D:\code\mysql_data\data\"  

  

port=3306  

server_id=1  

  

general-log=0  

general_log_file="mysql_general.log"  

slow-query-log=1  

slow_query_log_file="mysql_slow_query.log"  

long_query_time=10  

  

log-error="mysql_error_log.err"  

  

  

default-storage-engine=INNODB  

max_connections=1024  

query_cache_size=128M  

key_buffer_size=128M  

innodb_flush_log_at_trx_commit=1  

innodb_thread_concurrency=128  

innodb_autoextend_increment=128M  

tmp_table_size=128M  

  

  

# Remove leading # to set options mainly useful for reporting servers.  

# The server defaults are faster for transactions and fast SELECTs.  

# Adjust sizes as needed, experiment to find the optimal values.  

# join_buffer_size = 128M  

# sort_buffer_size = 2M  

# read_rnd_buffer_size = 2M   

  

#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES   

sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"  

character-set-server=utf8  

其中

[html] view
plaincopy

[WinMySQLAdmin]   

Server=D:/code/mysql-5.6.10-winx64/bin/mysqld.exe  

组是我net start mysql后控制台提示出错,找不到指定文件后添加的,

[html] view
plaincopy

explicit_defaults_for_timestamp = TRUE  

属性是mysqld --install MySQL --defaults-file=D:\code\mysql_data\my.ini后提示

[html] view
plaincopy

[Warning] TIMESTAMP with implicit DEFAULT value is deprecated.  

Please use --explicit_defaults_for_timestamp server option (see  

documentation for more details).  

添加的,

[html] view
plaincopy

basedir="D:\code\mysql-5.6.10-winx64\"  

datadir="D:\code\mysql_data\data\"  

分别指向MySQL的程序目录和数据目录,注意写路径时可能出现的一些错误,如双引号、路径分隔符,其余的属性主要是优化MySQL配置的,可以通过show status查看;

7、输入mysqld --install MySQL --defaults-file=D:\code\mysql_data\my.ini命令,将mysql作为win系统服务,如果出错或想重命名服务名,可以mysqld --remove,具体可以看http://dev.mysql.com/doc/refman/5.1/en/windows-start-service.html

8、输入net start mysql启动服务;

OK,现在就可以通过mysql -h127.0.0.1 -P3306 -utest -p来跑数据库了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: