【Window10】MySQL 8.0.16 安装&配置

1、下载地址:https://dev.mysql.com/downloads/mysql/

2、解压zip到安装路径

       D:\Program_Files(本人安装路径)

3、新建配置文件my.ini(存储在安装目录下的根目录下,eg:D:\Program_Files\mysql-8.0.16-winx64\my.ini)

[mysqld]

# 设置3306端口

port=3306

# 设置mysql的安装目录

basedir=D:\Program_Files\mysql-8.0.16-winx64

# 设置mysql数据库的数据的存放目录

datadir=D:\Program_Files\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

[mysql]

# 设置mysql客户端默认字符集

default-character-set=utf8mb4

[client]

# 设置mysql客户端连接服务端时默认使用的端口

port=3306

4、初始化数据库

以管理员身份运行cmd(注:必须以管理员身份),在C:\Windows\System32目录下找到cmd.exe,进入在MySQL安装目录的 bin 目录下执行命令:

mysqld --initialize --console

执行完成之后,会打印 root 用户的初始默认密码,比如:

D:\MySQL\mysql-8.0.13-winx64\bin>mysqld --initialize --console

  • 2018-10-30T09:47:22.079528Z 0 [System] [MY-013169] [Server] D:\Program_Files\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.13) initializing of server in progress as process 40936
  • 2018-10-30T09:47:22.080771Z 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.
  • 2018-10-30T09:47:25.480866Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: f0,_wUSV!VuG
  • 2018-10-30T09:47:26.882440Z 0 [System] [MY-013170] [Server]D:\Program_Files\mysql-8.0.16-winx64\bin\mysqld.exe (mysqld 8.0.13) initializing of server has completed

注意:[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: f0,_wUSV!VuG 其中root@localhost:后面的“f0,_wUSV!VuG”就是初始密码(不含首位空格)。在没有更改密码前,需要记住这个密码,后续登录使用。

  如果没记住,那也没事,删掉初始化的 datadir 目录,再执行一遍初始化命令,又会重新生成的。当然,也可以使用安全工具,强制改密码,用什么方法,自己随意。

5、安装服务

在MySQL安装目录的 bin 目录下执行命令(以管理员身份打开cmd命令行):

mysqld --install [服务名]

后面的服务名可以不写,默认的名字为 MySQL。当然,如果你的电脑上需要安装多个MySQL服务,就可以用不同的名字区分了,比如 mysql1 和 mysql2。

安装完成之后,就可以通过命令net start mysql启动MySQL的服务了。

 

    • D:\Program_Files\mysql-8.0.16-winx64\bin>mysqld --install
    • Service successfully installed.
    • D:\Program_Files\mysql-8.0.16-winx64\bin>net start
    • mysqltest1 服务正在启动 .mysqltest1 服务已经启动成功。
    • D:\Program_Files\mysql-8.0.16-winx64\

6、更改密码

修改密码:

登录服务器,输入:

mysql -uroot -p

提示输入密码:密码在四中的初始化数据库之后,[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: f0,_wUSV!VuG,其中的“ f0,_wUSV!VuG”为默认密码;

输入如下命令,其中的“123456”为我的密码:

ALTER USER 'root'@'localhost' IDENTIFIED BY "123456";

如下:

D:\Program_Files\mysql-8.0.16-winx64\bin>mysql -uroot -p

Enter password: ************

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 9

Server version: 8.0.16

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.06 sec)

mysql>

截止目前,默认密码修改完毕;可使用SQLyog、Navicat等客户端进行登录使用;

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章