1、把下载得到的mysql安装包解压后得到如下目录结构
D:\JackGao\Downloads\mysql-5.7.10-winx64\bin
2、修改ini文件:D:\JackGao\Downloads\mysql-5.7.10-winx64\my-default.ini
在[mysqld]后面添加
basedir=D:\JackGao\Downloads\mysql-5.7.10-winx64
datadir=D:\JackGao\Downloads\mysql-5.7.10-winx64\data
port=3306
#这一句解决有IPV6协议的计算机上默认采用IPV6协议导致无法从程序连接数据库的问题
bind-address=127.0.0.1
# 允许最大连接数
max_connections = 200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server = utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine = INNODB
[client]
# 设置mysql客户端默认字符集
default-character-set = utf8
3、mysql5.7.10没有data目录,所以要初始化,如果datadir指向的data目录不存在,初始化的时候会新建
cmd> bin/mysqld --initialize-insecure --defaults-file=D:\JackGao\Downloads\mysql-5.7.10-winx64\my-default.ini
4、启动mysqld,并且修改root密码,关闭mysql直接关掉cmd窗口即可
cmd> mysqld --console
cmd> mysql -u root --skip-password
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
5、安装mysqld服务,也可以不安装服务
cmd> cd /d D:\JackGao\Downloads\mysql-5.7.10-winx64\bin
cmd> mysqld -install mysql --defaults-file="D:\JackGao\Downloads\mysql-5.7.10-winx64\my-default.ini"
cmd> mysqld -remove mysql
启动mysql
cmd> net start mysql
关闭mysql
cmd> net stop mysql
安装结束
参考资料:
http://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization-mysqld.html
-------------
The database must be initialized before MySQL can be started. For additional information about the initialization process, see Section 2.10.1.1, “Initializing the Data Directory Manually Using mysqld”.
To start the mysqld server from the command line, you should start a console window (or “DOS window”) and enter this command:
C:\> "C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld"
The path to mysqld may vary depending on the install location of MySQL on your system.
You can stop the MySQL server by executing this command:
C:\> "C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqladmin" -u root shutdown
-------------
2015-12-15T14:15:10.506825Z 0 [Note] InnoDB: not started
mysqld: Table 'mysql.plugin' doesn't exist
2015-12-15T14:15:10.510825Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2015-12-15T14:15:10.539827Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2015-12-15T14:15:10.540827Z 0 [ERROR] Aborting
shell> bin/mysqld --initialize (--console这个选项是把日志输出到命令行,否则就会把日志输出到datadir目录的xx.err文件中)
shell> bin/mysqld --initialize-insecure
Regardless of platform, use --initialize for “secure by default” installation (that is, including generation of a random initial root password). In this case, the password is marked as expired and you will need to choose a new one. With the --initialize-insecure option, no root password is generated; it is assumed that you will assign a password to the account in timely fashion before putting the server into production use.
-------------------------------