1、下载免安装版压缩包
下载地址:http://dev.mysql.com/downloads/mysql/
- 选择符合你的操作系统的版本,点击download进入下载页面
- 不用注册也可以点击下载连接进行下载
2、安装
-
解压下载的压缩文件到你的mysql安装目录(目录能不能有中文没测试过,你可以试一下),以下是我的解压目录
- 复制解压目录D:javaEnvironmentmysql-5.7.12-winx64下的my-default.ini命名为my.ini,打开my.ini添加如下配置、保存:
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/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. [client] default-character-set=utf8 [mysqld] # 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 = 128M # 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. #skip-grant-tables basedir = "D:javaEnvironmentmysql-5.7.12-winx64" datadir = "D:javaEnvironmentmysql-5.7.12-winx64data" tmpdir = "D:javaEnvironmentmysql-5.7.12-winx64data" socket = "D:javaEnvironmentmysql-5.7.12-winx64datamysql.sock" port = 3306 log-error = "D:javaEnvironmentmysql-5.7.12-winx64datamysql_error.log" # server_id = ..... max_connections = 100 table_open_cache = 256 query_cache_size = 1M tmp_table_size = 32M thread_cache_size = 8 innodb_data_home_dir = "D:javaEnvironmentmysql-5.7.12-winx64data" innodb_flush_log_at_trx_commit = 1 innodb_log_buffer_size = 128M innodb_buffer_pool_size = 128M innodb_log_file_size = 10M innodb_thread_concurrency = 16 innodb-autoextend-increment = 1000 # 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 = 32M read_rnd_buffer_size = 32M max_allowed_packet = 32M explicit_defaults_for_timestamp = true sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
- 设置环境变量,在环境变量path变量中后面添加上上面的mysql解压目录的bin路劲D:javaEnvironmentmysql-5.7.12-winx64in,注意添加前加上‘;’号
- win+r,输入cmd进入windows Dos界面
- 进入解压的/bin目录下,(重要)执行命令mysqld --initialize,5.7之后需要初始化生成数据库文件(根目录下的data文件),否则后续无法启动服务
- 执行命令mysqld -install,安装mysql服务
- 执行命令net start mysql,启动服务
- 执行命令mysql -uroot -p,会报错ERROR 1045(28000),需要设置登录密码
- 打开配置文件my.ini,将skip-grant-tables前面的#去掉,然后重启服务,再次登录就可略过密码
-
进入mysql数据库,依次执行以下命令:
use mysql;
update user set authentication_string=password("root") where user="root"; //注意:这里"root"修改为你的密码,如:"123456"
flush privileges;
quit;
- 打开配置文件my.ini,在skip-grant-tables前面加上#注释掉,然后重启服务,使用设置的密码再次登录
- mysql登陆后执行:SET PASSWORD = PASSWORD('123456'); 原因参考官网说明:http://dev.mysql.com/doc/refman/5.6/en/alter-user.html。(ps:英文不好,没看懂,看懂的可以给我指点一下)
- 然后就可以在版本的mysql客户端SQLyog中连接mysql server了,但是这时候别的机器还不能访问本机的mysql server,如下三步操作解决问题:
- use mysql; //进入mysql数据库
- update user set host = '%' where user = 'root'; //可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"
- GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; //赋予任何主机访问数据的权限
- FLUSH PRIVILEGES //修改生效