操作系统环境
windows 10
MyQL 版本
8.0.16
操作步骤
1、下载
直接去官方网站下载压缩包即可
https://dev.mysql.com/downloads/mysql/
下载对应操作系统的版本
解压文件到指定的目录
2、初始化
用系统管理员身份运行命令行工具CMD
你的路径/mysql/bin
进入mysql\bin目录,运行初始化命令
mysqld --initialize --user=root --console
注意在初始化的过程中会产生一个临时密码
D:\mysql\mysql-8.0.16-winx64\bin>mysqld --initialize --user=root --console
2019-06-03T09:41:19.439548Z 0 [System] [MY-013169] [Server] D:\mysql\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.16) initializing of server in progress as process 13200
2019-06-03T09:41:49.416995Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: )j?t,Z%f!7+<
2019-06-03T09:42:00.999372Z 0 [System] [MY-013170] [Server] D:\mysql\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.16) initializing of server has completed
3、 修改密码
用上一步生成的临时密码,登录mysql
D:\mysql\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 13
Server version: 8.0.16
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
执行修改密码的命令
alter user 'root'@'localhost'IDENTIFIED BY '你的新密码';
4、my.ini配置
默认没有此配置文件,自行在mysql的根目录创建即可,例如:D:\mysql\mysql-8.0.16-winx64\my.ini
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=D:\mysql\mysql-8.0.16-winx64
# 设置mysql数据库的数据的存放目录
datadir=D:\mysql\mysql-8.0.16-winx64\data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。
max_connect_errors=10
# 服务端使用的字符集默认为utf8mb4
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
#mysql_native_password
default_authentication_plugin=mysql_native_password
#时区设置
default-time_zone = '+8:00'
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8mb4
常见异常
Q1:Public Key Retrieval is not allowed
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Public Key Retrieval is not allowed
Q1:解决方案
DBeaver中直接设置 allowPublicKeyRetrieval=true
链接异常01.png
Q2:时区异常
The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than
Q2:解决方案
show variables like '%time_zone%';
set global time_zone='+8:00';
Q3:Host is not allowed to connect to this MYSQL server:
链接被拒绝
Q3:解决方案
update user set host = '%' where user ='root';
本人很懒,记录避免下次再次搜索
网友评论