Windowsserver2012下安装MySQL记录

一、配置系统环境变量

变量名:MYSQL_HOME

变量值:C:\mysql-8.0.28-winx64

 

 

 

二、生成数据data文件

以管理员身份运行cmd

进入mysql安装包的解压文件夹:

在C:\mysql-8.0.28-winx64\bin目录下生成data目录

PS C:\Users\Administrator> cd C:\mysql-8.0.28-winx64\bin
PS C:\mysql-8.0.28-winx64\bin> mysqld --initialize-insecure --user=mysql

执行命令后报错:
mysqld : 无法将“mysqld”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路
正确,然后再试一次。
所在位置 行:1 字符: 1
+ mysqld --initialize-insecure --user=mysql
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (mysqld:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Suggestion [3,General]: 未找到命令 mysqld,但它确实存在于当前位置。Windows PowerShell 默认情况下不从当前位置加载命令
果信任此命令,请改为键入 ".\mysqld"。有关更多详细信息,请参阅 "get-help about_Command_Precedence"。

按照提示输入命令,继续执行命令:

PS C:\mysql-8.0.28-winx64\bin> ./mysqld --initialize-insecure --user=mysql
PS C:\mysql-8.0.28-winx64\bin> ./mysqld -install
Service successfully installed.

启动服务
PS C:\mysql-8.0.28-winx64\bin> net start Mysql
MySQL 服务正在启动 ..
MySQL 服务已经启动成功。

三、登录mysql数据库,增删改查:

PS 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 8
Server version: 8.0.28 MySQL Community Server - GPL

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> select host,user,authentication_string from mysql.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 | |
+-----------+------------------+------------------------------------------------------------------------+
4 rows in set (0.00 sec)

mysql> use mysql;
Database changed

mysql> ALTER USER 'root'@'localhost' 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)

四、通过navicate连接mysql数据库,提示不被允许的IP连接

mysql> use mysql;
Database changed
mysql> select host from user where user='root';
+-----------+
| host |
+-----------+
| localhost |
+-----------+
1 row in set (0.00 sec)

mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select host from user where user='root';
+------+
| host |
+------+
| % |
+------+
1 row in set (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

连接成功:

 

posted on 2022-09-06 17:12  一语惊呆众人  阅读(391)  评论(0)    收藏  举报