1、安装包下载。
下载地址:https://dev.mysql.com/downloads/mysql/
点击下载之后,可以选择注册Oracle账号,也可以跳过直接下载。
下载完成后,选择一个磁盘内放置并解压。
下载完成之后,找到下载的路径,解压即可!
2 安装教程
(1)配置环境变量
变量名:MYSQL_HOME
变量值:C:\software
(2)生成data文件
以管理员身份运行cmd
进入C:\software\mysql-8.0.19-winx64.zip\mysql-8.0.19-winx64\bin下
执行命令:mysqld --initialize-insecure --user=mysql 在C:\software\mysql-8.0.19-winx64.zip\mysql-8.0.19-winx64下和bin同级目录生成data目录
(3) 安装MySQL
继续执行命令:mysqld -install
(4)启动服务
继续执行命令:net start MySQL
(5)登录MySQL
登录mysql:(因为之前没设置密码,所以密码为空,不用输入密码,直接回车即可)
mysql -u root -p
(6)查询用户密码
查询用户密码命令:mysql> select host,user,authentication_string from mysql.user;
(7)设置(或修改)root用户密码
mysql> use mysql
提别注意:下面这个修改密码的方式不正确,可能是因为版本问题。最近解决了。
mysql> update mysql.user set authentication_string=("123456") where user="root";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
解决方案如下:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
mysql> flush privileges;
#作用:相当于保存,执行此命令后,设置才生效,若不执行,还是之前的密码不变
Query OK, 0 rows affected (0.01 sec)
(8)退出
mysql> quit
Bye
(9)再次登录
3、解决问题
C:\Windows\system32>cd ..
C:\Windows>cd ..
C:\>cd mysql
C:\mysql>cd bin
C:\mysql\bin>mysqld --install
Service successfully installed.
C:\mysql\bin>
C:\mysql\bin>mysqld --initialize --console
2020-12-02T09:09:29.334611Z 0 [System] [MY-013169] [Server] C:\mysql\bin\mysqld.exe (mysqld 8.0.22) initializing of server in progress as process 18944
2020-12-02T09:09:29.376137Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-12-02T09:09:30.581041Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-12-02T09:09:32.715621Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: _qj%i&3upyYi
C:\mysql\bin>
C:\mysql\bin>
C:\mysql\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
C:\mysql\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.22
Copyright (c) 2000, 2020, 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>
mysql> alter user 'root'@'localhost' identified by 'root'
-> ;
Query OK, 0 rows affected (0.01 sec)
mysql> mysql -u root -p
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql -u root -p' at line 1
mysql> exit
Bye
C:\mysql\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.22 MySQL Community Server - GPL
Copyright (c) 2000, 2020, 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> exit
Bye
C:\mysql\bin>alter user 'root'@'localhost' identified by 'maixiquan';
'alter' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
C:\mysql\bin>
C:\mysql\bin>mysql -u root -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.22 MySQL Community Server - GPL
Copyright (c) 2000, 2020, 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 'maixiquan';
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
C:\mysql\bin>mysql -u root -p
Enter password: *********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.22 MySQL Community Server - GPL
Copyright (c) 2000, 2020, 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>