美文网首页
MySQL 8.0.12-winx64 安装

MySQL 8.0.12-winx64 安装

作者: _fix_ | 来源:发表于2018-09-28 10:07 被阅读0次

1. 下载MySQL安装包

2. 解压到合适的安装位置

  • 我的解压位置:D:\MySQL\mysql-8.0.12-winx64

3. 配置环境变量

  • 新建系统变量:MySQL_HOME,值为安装包解压目录:D:\MySQL\mysql-8.0.12-winx64 (此处修改为你的解压目录)

  • 编辑系统变量Path,新增变量值:%MySQL_HOME%\bin

4. 新建my.ini

[mysql]
default-character-set=utf8

[mysqld]

# 以下两处修改为你的实际解压目录
# 设置MySQL的安装目录
basedir=D:\MySQL\mysql-8.0.12-winx64
# 设置MySQL的数据存放目录
datadir=D:\MySQL\mysql-8.0.12-winx64\data

port=3306
character-set-server=utf8

[client]  
default-character-set=utf8

  • 在MySQL_HOME目录下,复制以上代码,新建my.ini文件。以上只包含最基本配置(其他自定义配置可参考官方文档)

5. 初始化MySQL

  • 以管理员身份打开cmd命令窗口,切换到MySQL_HOME目录的bin目录下(重要)

执行初始化指令:mysqld --initialize --user=mysql --console

D:\MySQL\mysql-8.0.12-winx64\bin>mysqld --initialize --user=mysql --console
2018-09-28T01:35:41.013128Z 0 [System] [MY-013169] [Server] D:\MySQL\mysql-8.0.1
2-winx64\bin\mysqld.exe (mysqld 8.0.12) initializing of server in progress as pr
ocess 23840
2018-09-28T01:35:55.823149Z 5 [Note] [MY-010454] [Server] A temporary password i
s generated for root@localhost: dLFFgfFdF1(b
2018-09-28T01:36:03.603160Z 0 [System] [MY-013170] [Server] D:\MySQL\mysql-8.0.1
2-winx64\bin\mysqld.exe (mysqld 8.0.12) initializing of server has completed

  • 此处生成的随机密码为:dLFFgfFdF1(b(后续需要用到)

6. 安装并启动MySQL服务

执行安装指令:mysqld --install

启动服务:net start MySQL

D:\MySQL\mysql-8.0.12-winx64\bin>mysqld --install
Service successfully installed.

D:\MySQL\mysql-8.0.12-winx64\bin>net start MySQL
MySQL 服务正在启动 ..
MySQL 服务已经启动成功。

7.修改初始密码

执行指令:mysql -u root -p (回车之后输入随机密码)

修改密码:ALTER USER root@localhost IDENTIFIED BY '123456';

D:\MySQL\mysql-8.0.12-winx64\bin>mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.12

Copyright (c) 2000, 2018, 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> ALTER USER root@localhost IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.17 sec)

  • 修改完成之后,可以先退出,再使用新密码重新登录,验证是否修改成功

8.其他

  • 解除MySQL只能localhost连接

UPDATE mysql.user set host='%' WHERE user = 'root';

FLUSH PRIVILEGES;

mysql> UPDATE mysql.user SET host='%' WHERE user = 'root';
Query OK, 1 row affected (0.09 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

相关文章

网友评论

      本文标题:MySQL 8.0.12-winx64 安装

      本文链接:https://www.haomeiwen.com/subject/rkoigftx.html