1 环境信息
OS:Windows7
MySQL:社区版8.0.16
1 在mysql文件夹下新建my.ini文件和data文件夹
配置文件my.ini
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
# 设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=D:\Program Files (x86)\mysql-8.0.16-winx64
# 设置 mysql数据库的数据的存放目录,MySQL 8+ 不需要以下配置,系统自己生成即可,否则有可能报错
# datadir=C:\\web\\sqldata
# 允许最大连接数
max_connections=20
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
2 初始化
- 1 以管理员的身份打开cmd窗口跳转路径到D:\Program Files (x86)\mysql-8.0.16-winx64\bin
- 2 初始化命令mysqld --initialize --user=mysql --console
D:\Program Files (x86)\mysql-8.0.16-winx64\bin>mysqld --initialize --user=mysql --console
2019-06-12T22:29:56.740810Z 0 [System] [MY-013169] [Server] D:\Program Files (x86)
\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.16) initializing of server in progress as
process 2436
2019-06-12T22:29:56.756410Z 0 [ERROR] [MY-010457] [Server] --initialize specified but
the data directory has files in it. Aborting.
3 添加服务
- 输入mysqld -install进行服务的添加
D:\Program Files (x86)\mysql-8.0.16-winx64\bin>mysqld -install
The service already exists!
The current server installed: "D:\Program Files (x86)\mysql-8.0.16-winx64\bin\my
sqld" MySQL
4 启动服务
- 输入net start mysql启动服务
D:\Program Files (x86)\mysql-8.0.16-winx64\bin>net start mysql
MySQL 服务正在启动 ...
MySQL 服务已经启动成功。
5 登录
- 输入mysql -u root -p进行登录
D:\Program Files (x86)\mysql-8.0.16-winx64\bin>mysql -u root -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.16 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>