1、下载二进制安装包,选择其中一个即可
    https://dev.mysql.com/downloads/mysql/
    image.png

    2、直接解压后放在任意路径下,例如放在如下位置:
    C:\Program Files\mysql-8.0.17-winx64

    3、配置环境变量
    在环境变量->系统变量->path下添加C:\Program Files\mysql-8.0.17-winx64\bin(注意:替换为自己的安装路径,下同)

    4、配置my.ini文件
    在C:\Program Files\mysql-8.0.17-winx64下新建一个my.ini文件,写入如下代码。(如果提示没有权限修改,可在其他地方新建文件后拷贝至目标路径)
    注意:安装目录下的data不需要自己创建
    [mysql]
    # 设置mysql客户端默认字符集
    default-character-set=utf8
    [mysqld]
    #设置3306端口
    port = 3306
    #设置mysql的安装目录
    basedir=C:\Program Files\mysql-8.0.17-winx64
    # 设置mysql数据库的数据的存放目录
    datadir=C:\Program Files\mysql-8.0.17-winx64\data
    # 允许最大连接数
    max_connections=200
    # 服务端使用的字符集默认为8比特编码的latin1字符集
    character-set-server=utf8
    # 创建新表时将使用的默认存储引擎
    default-storage-engine=INNODB


    5、安装
    打开cmd(注意:以管理员身份运行),进入mysql文件存放路径下的bin目录,输入mysqld install,提示安装成功
    image.png

    可能出现的错误,服务已安装
    image.png

    解决办法:
    1>使用mysqld -remove MySQL命令删除Mysql
    2>删除原来的my.ini文件
    3>重新安装
    image.png

    6、初始化并启动服务
    先初始化:mysqld —initialize
    再输入net start mysql,提示启动成功
    image.png
    image.png

    可能出现的错误:服务无法启动,服务没有任何错误。
    image.png
    解决办法:检查以下操作:
    1>安装路径下的data文件无需自己创建
    2>以管理员身份运行cmd
    3>启动服务以前需要先初始化mysqld -initialize

    mysql安装:“root@localhost is created with an empty password !”,而非A temporary password is generated for
    Only One 666 2020-02-23 12:05:13 1493 收藏
    版权

    问题:在安装mysql时,打开DESKTOP-8UNK26K.err未发现密码,发现:

    [Warning] root@localhost is created with an empty password ! Please
    consider switching off the —initialize-insecure option.

    1. 1<br /> 2

    而非:

    [Warning] A temporary password is generated for root@localhost:
    **

    1. 1<br /> 2

    原因:
    mysql官网已经给出解决方案及原因:

    The server creates a ‘root’@’localhost’ superuser account and other reserved accounts (see Reserved Accounts). Some reserved accounts are locked and cannot be used by clients, but ‘root’@’localhost’ is intended for administrative use and you should assign it a password.

    Server actions with respect to a password for the ‘root’@’localhost’ account depend on how you invoke it:

    With —initialize but not —initialize-insecure, the server generates a random password, marks it as expired, and writes a message displaying the password:

    [Warning] A temporary password is generated for root@localhost:
    iTag*AfrH5ej
    With —initialize-insecure, (either with or without —initialize because —initialize-insecure implies —initialize), the server does not generate a password or mark it expired, and writes a warning message:

    [Warning] root@localhost is created with an empty password ! Please
    consider switching off the —initialize-insecure option.
    For instructions on assigning a new ‘root’@’localhost’ password, see Post-Initialization root Password Assignment.

    1. 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br /> 10<br /> 11<br /> 12<br /> 13

    大概意思就是,如果之前初始化数据库时使用的是–initialize-insecure 命令,那么就不会出现密码。如果以–initialize初始化数据库,就会出现密码。initialize意为“不安全的,不可靠的”,这也就解释了为什么加上他就没有出现密码,及root的密码为空。

    解决:
    1、删除自己创建的data文件夹
    2、以管理员身份cmd进入bin目录,关闭mysqld服务

    D:\Program ~\MySQL\bin>mysqld -remove MySQL
    Service successfully removed.

    1. 1<br /> 2

    3、在bin目录执行mysqld —initialize,程序会自动创建刚才删掉的那个文件夹
    4、在bin目录执行mysqld —install,重新安装mysql服务
    5、在bin目录运行net start mysal,启动mysql服务
    6、进入程序自动创建的那个文件夹,打开DESKTOP-8UNK26K.err,即可发现密码,问题解决
    ————————————————
    版权声明:本文为CSDN博主「Only One 666」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/qq_30039127/article/details/104457068

    7、登陆mysql
    第6步中初始化以后会在安装目录下的data文件中生成一个.err结尾的文件,打开后找到登陆时临时用的随机密码
    image.png
    登陆:mysql -u root -p ,将临时密码输入后即可登陆成功!
    image.png

    8、修改初始密码:
    方法1:报错,该操作命令与版本不符
    image.png
    方法2:报错,该操作命令与版本不符,提示需要通过ALTER USER语句
    image.png
    方法3:修改成功,下次即可使用新密码进行登陆
    image.png

    9、开始使用数据库
    image.png

    使用完以后输入命令quit退出mysql.