本文根据mysql官方手册整理完成。适用于8.0版本!
原文地址为https://dev.mysql.com/doc/refman/8.0/en/windows-install-archive.html
在微软的视窗操作系统中使用非安装版的压缩包安装mysql。
新建一个my.ini文件,内容如下所示:
(路径根据自己本地的实际进行录入。)
[mysqld]
# set basedir to your installation path
basedir=C:/dvp/mysql-8.0.18-winx64
# set datadir to the location of your data directory
datadir=C:/data/mysql
使用mysqld手动初始化data目录
执行mysqld命令如下所示:
C:/mysql/bin/mysqld --defaults-file=C:/mysql/my.ini --initialize --console
注意:如果命令执行失败,请以管理员的身份启动cmd,再执行以上的初始化命令。
注意保存控制台输出的随机密码。
[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: cf;0F=cecFxq
新建批处理文件,mysql.bat。写入内容并执行:
C:/MySQL/bin/mysqld --defaults-file=C:/mysql/my.ini --console
然后执行:mysql -u root --skip-password
在连接后,为root设置新的密码:
注意不要忘记录入最后的分号!两个命令都试一下。
mysql> ALTER USER USER() IDENTIFIED WITH mysql_native_password BY 'password';
或者
mysql>ALTER USER 'root' @ 'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';
系统会提示“Query OK, 0 rows affected (0.01 sec)”,没关系,这就是修改成功了。
注意:WITH mysql_native_password这个参数如果不加的话会报错。客户端连接可能会出现caching-sha2-password问题。
下载openssl在windows系统的安装包http://slproweb.com/products/Win32OpenSSL.html
设置环境变量。
生成密钥。
文件说明:
ca.pem Self-signed CA certificate
ca-key.pem CA private key
server-cert.pem Server certificate
server-key.pem Server private key
client-cert.pem Client certificate
client-key.pem Client private key
将生成的文件放到mysql/data文件夹。这样mysql启动后就自动启动ssl了。
You can test whether the MySQL server is working by executing any of the following commands:
C:\> "C:\MySQL\bin\mysqlshow"
C:\> "C:\MySQL\bin\mysqlshow" -u root mysql
C:\> "C:\MySQL\bin\mysqladmin" version status proc
C:\> "C:\MySQL\bin\mysql" test
If mysqld is slow to respond to TCP/IP connections from client programs, there is probably a problem with your DNS. In this case, start mysqld with the --skip-name-resolve option and use only localhost and IP addresses in the Host column of the MySQL grant tables. (Be sure that an account exists that specifies an IP address or you may not be able to connect.)
You can force a MySQL client to use a named-pipe connection rather than TCP/IP by specifying the --pipe or --protocol=PIPEoption, or by specifying . (period) as the host name. Use the --socket option to specify the name of the pipe if you do not want to use the default pipe name.
If you have set a password for the root account, deleted the anonymous account, or created a new user account, then to connect to the MySQL server you must use the appropriate -u and -p options with the commands shown previously. See Section 5.2.2, “Connecting to the MySQL Server”.
For more information about mysqlshow, see Section 5.5.7, “mysqlshow — Display Database, Table, and Column Information”.