在 Windows 上使用压缩文件 安装 MySQL
1. 下载 MySQL
mysql-5.7.27-win32.zip:二进制文件; 服务器类型: mysqld
2. 解压 mysql-5.7.27-win32.zip
3. 设置 配置文件 my.ini
没有新建一个( 里面涉及的目录没有的记得新建 )
[client]
no-beep
socket =0.0
port=2224
#设置mysql客户端连接服务端时默认使用的端口
[mysqld]
server-id=45
port=2224
character-set-server=utf8mb4
pid-file ="mysql.pid"
socket =0.0
basedir="E:\\Abai_Student\\DB\\Mysql\\mysql-5.7.27-win32"
datadir="E:\\Abai_Student\\DB\\Mysql\\mysql-5.7.27-win32\\Data"
tmpdir="E:\\Abai_Student\\DB\\Mysql\\mysql-5.7.27-win32\\Data"
default-storage-engine=INNODB
#创建新表时将使用的默认存储引擎
#=============================[log]==============================
slow-query-log=1
long_query_time=1
#下面的Log文件目录 是需要自己新建的
slow_query_log_file="E:\\Abai_Student\\DB\\Mysql\\mysql-5.7.27-win32\\Log\\mysql-slow.log"
#log-bin="E:\\Abai_Student\\DB\\Mysql\\mysql-5.7.27-win32\\Log\\mysql-bin"
log-error="E:\\Abai_Student\\DB\\Mysql\\mysql-5.7.27-win32\\Log\\mysql-error.log"
#服务器错误日志:mysql-error.log
4. 初始化数据目录 + 首次启动服务器
二选一:
bin\mysqld --initialize --console
bin\mysqld --initialize-insecure --console
之后你会在~\mysql-5.7.27-win32\Log\mysql-error.log中看到初始密码(最后一行):
......[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
......[Warning] InnoDB: New log files created, LSN=45790
......[Warning] InnoDB: Creating foreign key constraint system tables.
mysqld: File '\Log\mysql-slow.log' not found (Errcode: 2 - No such file or directory)
......[ERROR] Could not use \Log\mysql-slow.log for logging (error 2 - No such file or directory). Turning logging off for the server process. To turn it on again: fix the cause, then either restart the query logging by using "SET GLOBAL SLOW_QUERY_LOG=ON" or restart the MySQL server.
......[Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2e267fbb-8630-11eb-a30c-1c3947bd0d32.
......[Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
......[Note] A temporary password is generated for root@localhost: xshu5jytAo/h
5. 首次启动服务器(状态)可以跳过
cmd 进入到 mysql\bin 目录下
mysqld --console
当服务器完成其启动序列时,您应该会看到类似的东西,这表明服务器已准备好为客户端连接提供服务:
mysqld: ready for connections.
Version: '5.7.27-log' socket: '' port: 2224 MySQL Community Server (GPL)
6. 登录 MySQL & 修改密码
- cmd 进入
bin目录下:
mysql -u root -p password
- 进入 mysql 后设置新密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-password';
- 重新登录 MySQL 测试一下
7. 为 MySQL 创建环境变量
为了更轻松地调用 MySQL 程序,您可以将 MySQL 目录的路径名称添加到您的 Windows 系统环境变量中
- 在 Windows 桌面上,右键单击
我的计算机图标,然后选择属性 - 接下来从显示的
系统属性菜单中选择高级选项卡,然后单击环境变量按钮 - 在
系统变量下,双击PATH,然后输入 MySQL 目录的完整路径名称(例如:C:\Program Files\MySQL\MySQL Server 5.7\bin)
8. 启动 MySQL 作为窗口服务(关掉所有cmd,重新开一个)
- 将服务器安装为服务(cmd) 以管理员身份启动!
mysqld --install
- 启动服务
net start mysql
- 删除服务
SC DELETE mysql
或者是
mysqld --remove
浙公网安备 33010602011771号