记一次win10 下安装 mysql8

 
社区版 https://dev.mysql.com/downloads/mysql/,选择 8.0版本。下载64位 zip 压缩包。
 
 
 
解压,新建my.ini文件。
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=C:\mysql-8.0.28-winx64
# 设置mysql数据库的数据的存放目录
datadir=C:\mysql-8.0.28-winx64\data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8

 

 
使用管理员权限启动cmd命令行窗口,cd目录到解压缩的路径下。
接下来执行初始化和安装为windows服务。红色标志的root的初始密码,要做记录。
 
C:\mysql-8.0.28-winx64\bin>mysqld.exe --initialize --user=mysql --console
2022-01-29T03:38:55.366891Z 0 [System] [MY-013169] [Server] C:\mysql-8.0.28-winx64\bin\mysqld.exe (mysqld 8.0.28) initializing of server in progress as process 13468
2022-01-29T03:38:55.368851Z 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.
2022-01-29T03:38:55.403946Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-01-29T03:38:58.628854Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-01-29T03:39:02.473327Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 9f3*pW5w5PgC
 
 
C:\mysql-8.0.28-winx64\bin>mysqld.exe -install mysql
Service successfully installed.
 
C:\mysql-8.0.28-winx64\bin>net start mysql
mysql 服务正在启动 .
mysql 服务已经启动成功。

 

 
 
 
改密码操作。
C:\mysql-8.0.28-winx64\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.28
 
 
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
 
 
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.01 sec)
 
 
mysql> quit
Bye
 
允许远程连接mysql
mysql> use mysql ;
Database changed
 
mysql> select * from user\G;
*************************** 1. row ***************************
                    Host: localhost
                    User: mysql.infoschema
             Select_priv: Y
 
mysql> select Host,User,authentication_string from user;
+-----------+------------------+------------------------------------------------------------------------+
| Host      | User             | authentication_string                                                  |
+-----------+------------------+------------------------------------------------------------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root             | $A$005$6MT*%o50b&3tNhDX!Q136dIVnRpMvoYOIdxtd1KMv2nz2Vl5yyONdmEfIc/5 |
+-----------+------------------+------------------------------------------------------------------------+
4 rows in set (0.00 sec)
 
 
mysql> update user set Host='%' where User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
 
测试连接
 
竟然报错。
继续使用管理员权限,执行cmd命令。
mysql> use mysql;
Database changed
mysql> alter user 'root'@'%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.00 sec)
 
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
 
mysql> quit
Bye

 

至此终于连接成功。
 
posted on 2022-03-11 15:23  wuyicode  阅读(70)  评论(0编辑  收藏  举报