在 Windows7 上按照 MySQL5.7 1、从官网下载最新版本的 MySQL,这里下载的是 mysql-5.7.17-win32; 2、将下载的 mysql-5.7.17-win32.zip 解压到指定的文件夹下,这里的目标文件夹是 E:develop; 3、复制 my-default.ini 文件并将新的文件命名为 my.ini; 4、根据自己的 MySQL 解压到的目录配置 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] character-set-server=utf8 collation-server=utf8_general_ci port=3306 basedir ="E:developmysql-5.7.17-win32" datadir ="E:developmysql-5.7.17-win32/data/" tmpdir ="E:developmysql-5.7.17-win32/data/" socket ="E:developmysql-5.7.17-win32/data/mysql.sock" log-error="E:developmysql-5.7.17-win32/data/mysql_error.log" #server_id = 2 #skip-locking max_connections=100 table_open_cache=256 query_cache_size=1M tmp_table_size=32M thread_cache_size=8 innodb_data_home_dir="E:developmysql-5.7.17-win32data" 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 join_buffer_size = 128M sort_buffer_size = 32M read_rnd_buffer_size = 32M max_allowed_packet = 32M explicit_defaults_for_timestamp=true sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" #sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES #################### 配置文件结束 ################### 5、配置 MySQL 的环境变量,在系统区域创建 MySQL_HOME 变量,值为 MySQL 的安装目录,这里的是 E:developmysql-5.7.17-win32; 将 MySQL_HOME 加入到 path 变量中,即 %MySQL_HOME%in; 6、以管理员身份打开命令行工具 CMD 并进入到 MySQL 的命令 bin 目录,这里为 E:developmysql-5.7.17-win32in; 7、执行如下命令: 7.1 mysqld --initialize --user=mysql --console 创建用户表,生成如下信息: E:developmysql-5.7.17-win32in>mysqld --initialize --user=mysql --console 2017-01-04T01:02:43.711502Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'E RROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2017-01-04T01:02:44.326080Z 0 [Warning] InnoDB: New log files created, LSN=45790 2017-01-04T01:02:44.675125Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2017-01-04T01:02:44.791639Z 0 [Warning] No existing UUID has been found, so we a ssume that this is the first time that this server has been started. Generating a new UUID: 802e6595-d219-11e6-bcf8-10604b7f46dc. 2017-01-04T01:02:44.806141Z 0 [Warning] Gtid table is not ready to be used. Tabl e 'mysql.gtid_executed' cannot be opened. 2017-01-04T01:02:44.814642Z 1 [Note] A temporary password is generated for root@ localhost: tFhwFqiA)0oQ 其中的 tFhwFqiA)0oQ 为 MySQL 为我们生成的临时密码,一定要记下来,后面要用到; 7.2 安装服务:
mysqld install MySQL --defaults-file="E:developmysql-5.7.17-win32my.ini"
7.3 启动服务:
net start mysql 7.4 进入到 MySQL 命令行界面: mysql -uroot -p
在提示下输入步骤 7.1 中生成的临时密码;
7.5 修改用户 root 的密码(必须修改,不然无法通过): set password = password('123456') 8、查看 MySQL 的字符编码: SHOW VARIABLES LIKE '%character%'; mysql> SHOW VARIABLES LIKE '%character%'; +--------------------------+-----------------------------------------------+ | Variable_name | Value | +--------------------------+-----------------------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | E:developmysql-5.7.17-win32sharecharsets | +--------------------------+-----------------------------------------------+ 8 rows in set, 1 warning (0.00 sec) 说明我们的字符编码配置都为 UTF8。 9、好了,至此我们完成了 MySQL 的安装,开始愉快的编程之旅吧!