- MySQL 下载、安装、配置:
1.1 下载地址:https://dev.mysql.com/downloads/mysql/
1.2 解压、配置文件:解压至C盘’web’文件夹,
在mysql-8.0.17文件夹下新增配置文件"my.ini":
[client]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
# 设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=C:\\web\\mysql-8.0.17
# 设置 mysql数据库的数据的存放目录,MySQL 8+ 不需要以下配置,系统自己生成即可,否则有可能报错
# datadir=C:\\web\\sqldata
# 允许最大连接数
max_connections=20
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
1.3数据库初始化、安装、启动
#切换目录
cd C:\web\mysql-8.0.17\bin
#数据库初始化,初始化完成后会输出用户名及密码
mysqld --initialize --console
# 数据库安装
mysqld install
#数据库启动
net start mysql
#待解决问题:若根用户密码忘记,再次初始化能否覆盖之前的用户名与密码
#再次初始化,报错信息
C:\web\mysql-8.0.17\bin>mysql --initialize --console
mysql: [ERROR] unknown option '--initialize'.
C:\web\mysql-8.0.17\bin>mysqld --initialize --console
2019-08-06T12:38:51.917931Z 0 [System] [MY-013169] [Server] C:\web\mysql-8.0.17\bin\mysqld.exe (mysqld 8.0.17) initializing of server in progress as process 16740
2019-08-06T12:38:51.923761Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2019-08-06T12:38:51.925938Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2019-08-06T12:38:51.925976Z 0 [ERROR] [MY-013236] [Server] The designated data directory C:\web\mysql-8.0.17\data\ is unusable. You can remove all files that the server added to it.
2019-08-06T12:38:51.939936Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-08-06T12:38:51.940969Z 0 [System] [MY-010910] [Server] C:\web\mysql-8.0.17\bin\mysqld.exe: Shutdown complete (mysqld 8.0.17) MySQL Community Server - GPL.
1.4 登陆数据库:
#按如下格式输入命令行
mysql -h 主机名 -u 用户名 -p # mysql -u root -p 连接本机数据库
#根据提示输入密码即可登陆
# e.g.
C:\web\mysql-8.0.17\bin>mysql -u root -p
Enter password: ***********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.17 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 curren