window 环境mysql8.0.4以上版本的安装配置
- mysql 最新版下载:https://dev.mysql.com/downloads/mysql/
- 解压zip包到指定路径(E:\work\mysql\)
- 创建数据库数据文件存放目录(E:\cache\mysqldata\)
- 在安装目录(E:\work\mysql)下新建my.ini 或my-default.ini 文件:
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=E:\work\mysql
# 设置mysql数据库的数据的存放目录
datadir=E:\cache\mysqldata
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8
-
数据库初始化
在bin目录(E:\work\mysql\bin\)的路径栏输入cmd调起命令行窗口,
mysqld --initialize --console
执行结果如下即表示成功:
E:\work\mysql\bin>mysqld --initialize --console
2019-05-15T09:37:51.704488Z 0 [System] [MY-013169] [Server] E:\work\mysql\bin\mysqld.exe (mysqld 8.0.16) initializing of server
in progress as process 7288
2019-05-15T09:37:51.715489Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the charac
ter set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2019-05-15T09:38:25.248407Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: iLDrqlh7q?iM
2019-05-15T09:38:34.596941Z 0 [System] [MY-013170] [Server] E:\work\mysql\bin\mysqld.exe (mysqld 8.0.16) initializing of server
has completed
其中root@localhost: iLDrqlh7q?iM
中iLDrqlh7q?iM
即为root账户初始密码。更改密码之前,此密码最好记住
-
mysql服务安装
mysqld --install
执行结果如下即表示成功:
E:\work\mysql\bin>mysqld --install
Service successfully installed.
安装时候由于之前版本卸载不完全造成失败怎么办
E:\work\mysql\bin>mysqld --uninstall
The service already exists!
The current server installed: E:\work\mysql5.7x64\bin\mysqld MySQL
这种情况可以使用命令sc query mysql
查看mysql服务,并使用 sc delete mysql
删除,然后再执行mysqld --install
即可。
E:\work\mysql\bin>sc query mysql
SERVICE_NAME: mysql
TYPE : 10 WIN32_OWN_PROCESS
STATE : 1 STOPPED
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
E:\work\mysql\bin>sc delete mysql
[SC] DeleteService 成功
-
启动MySQL服务
net start mysql
执行结果如下即表示成功:
E:\work\mysql\bin>net start mysql
MySQL 服务正在启动 ....
MySQL 服务已经启动成功。
-
修改初始密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码'
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.10 sec)
至此,mysql服务就已经安装、配置、启动好了。
-
使用MySql Workbench操作数据库
MySql Workbench中新建连接:
双击新建的连接,输入密码,即可进入数据库: