Installation under Windows zip version MySQL8

1. Go to the official website to download a MySQL Community Edition (Community) installation package, the latest version is 8.0.16

https://dev.mysql.com/downloads/mysql/

 

 

2. Create a directory, unzip the MySQL installation package. Note that the new directory must have read and write access, such as Common Program Files directory possible installation fails, reported unknown option '--install' error

 

Such as this create a directory Program will extract to the MySQL directory

 

 

3. Create a configuration file my.ini

 

Download MySQL installation package does not contain this file. Of course, under no circumstances can this document be installed, but if you need to customize some configuration, you can create one yourself. The following are some of the more basic configuration

 

[mysql]

default-character-set=utf8mb4

 

[mysqld]

#The port number

port=3306

#MySQL installation directory

basedir=C:\Program\mysql-8.0.16-winx64

# Data Directory

datadir=C:\UserData\MySQL

# Maximum number of connections allowed

max_connections=15

# Connection failures

max_connect_errors=10

# Server character set is utf8

character-set-server=utf8mb4

collation-server=utf8mb4_unicode_ci

# The default storage engine

default-storage-engine=INNODB

 

[client]

# Set the client character set

default-character-set=utf8mb4

 

The my.ini configuration, create the corresponding data directory path where the installation directory basedir is MySQL, DATADIR data storage directory.

 

Also note: datadir need to pre-create directory, otherwise an error when installing That might MySQL does not automatically create a directory in the installation according to my.ini configuration.

 

 

The initialization data directory

 

进入MySQL\bin目录, 执行mysqld --initialize-insecure. 稍等约10多秒20秒左右, 可能没有任何提示便结束. 如果中间没有报错就是成功了

      

这时去看我们定义的datadir目录, 初始化数据已经创建好了

 

 

6. 安装为Windows服务

以管理员运行CMD, 进入MySQL\bin目录, 执行

mysqld --install mysql8 --defaults-file=C:\Program\mysql-8.0.16-winx64\my.ini

其中mysql8为服务名, 即windows服务管理里面看到的名称, 可以自己定义

 

提示Service successfully installed 服务成功安装

 

 

7. 启动与关闭服务

启动服务: net start mysql8

mysql已经成功启动

 

 

关闭服务: net stop mysql8

 

 

8. mysql命令加入环境变量path

MySQL已经安装完成也能启动了, 但是现在除了mysql\bin目录下, 系统还不认识mysql命令. 所以需要将mysql\bin目录加入环境变量

 

依次找到 系统属性 -> 高级 选项卡 -> 环境变量, 在系统变量下选中path一行, 点击编辑, 将mysql\bin目录的完整路径粘贴进去

 

 

9. 首次登录

再运行mysql命令就不会报错了. 但是直接执行mysql是以odbc身份登录的, 所以需要指定用户名. 注意选项-u和用户名root之间没有空格

mysql -uroot

 

这时可以成功登录了.

 

再来看一下现在有哪些用户

select host, user from mysql.user;

 

到此MySQL就安装完成了

 

 

10. 可能遇到的问题:

unknown option '--install'

安装为windows服务的时候出现此错误, 原因为mysql解压的目录没有权限. 比如将mysql解压到C:\Program Files, 有可能出现此问题. 重新选择一个解压目录即可

 

mysqld: Can't create directory 'C:\UserData\MySQL\' (OS errno 2 - No such file or directory)

初始化数据目录的时候出现此错误, 原因为my.ini中配置了上述目录, 但实际上该目录并不存在. 所以需要根据配置路径, 预先创建对应的目录. Mysql初始化过程中并不会自动创建目录

 

缺少DLL msvcp140.dll

原因为缺少VC运行库. 安装Visual C++ Redistributable for Visual Studio 2015即可. 微软官网下载一个vc_redist.x64.exe

 

mysqld: [ERROR] Found option without preceding group in config file C:\Program\mysql8\my.ini at line 1.

mysqld: [ERROR] Fatal error in defaults handling. Program aborted!

原因可能是my.ini文件编码不对. 比如有的文本编辑器默认以UTF-8保存. 改为ANSI编码即可

发布了8 篇原创文章 · 获赞 62 · 访问量 9万+

Guess you like

Origin blog.csdn.net/wanghailong_qd/article/details/93216555