MySQL 安装与调试
- 下载MYSQL
官 网 地 址 :https://dev.mysql.com/downloads/mysql/
以下路径 和 密码均为示例 供参考
2 解压缩后 存放在E盘根目录下
E:\mysql
3.增加环境变量
系统环境变量
新建
E:\mysql\bin
4. 进入mysql 路径 安装MYSQL
[Server] A temporary password is generated for root@localhost: ut%?uytfXXXXX
启动cmd 命令提示行 需要 以系统管理员身份运行
E:\mysql\bin>mysqld -remove mysql
The service doesn't exist!
E:\mysql\bin>mysqld --initialize --user=mysql --console
2022-08-23T03:08:19.653672Z 0 [System] [MY-013169] [Server] E:\mysql\bin\mysqld.exe (mysqld 8.0.21) initializing of server in progress as process 2580
2022-08-23T03:08:19.655559Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2022-08-23T03:08:19.655567Z 0 [ERROR] [MY-013236] [Server] The designated data directory E:\mysql\data\ is unusable. You can remove all files that the server added to it.
2022-08-23T03:08:19.656156Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-08-23T03:08:19.656361Z 0 [System] [MY-010910] [Server] E:\mysql\bin\mysqld.exe: Shutdown complete (mysqld 8.0.21) MySQL Community Server - GPL.
需要把 mysql 文件夹下面的data文件删除后 重新执行
E:\mysql\bin>mysqld --initialize --user=mysql --console
2022-08-23T03:09:01.800988Z 0 [System] [MY-013169] [Server] E:\mysql\bin\mysqld.exe (mysqld 8.0.21) initializing of server in progress as process 11356
2022-08-23T03:09:01.809661Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-08-23T03:09:02.407350Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-08-23T03:09:03.554802Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: J(*VF1<IWWWWW
E:\mysql\bin>mysqld --install MySQL --defaults-file="E:\mysql\my.ini"
Service successfully installed.
E:\mysql\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务无法启动。
服务没有报告任何错误。
请键入 NET HELPMSG 3534 以获得更多的帮助。
E:\mysql\bin>sc delete mysql
[SC] DeleteService 成功
E:\mysql\bin>mysqld -install mysql
Service successfully installed.
E:\mysql\bin>net start mysql
mysql 服务正在启动 .
mysql 服务已经启动成功。
5.登录mysql 并修改 root 用户 密码
方法1 alter user root@localhost identified by 'yourpassword';
方法2 alter user 'root'@'%' identified with mysql_native_password by 'yourpassword';
alter user 'root'@'%' identified with mysql_native_password by 'yourpassword';
使用 % 还是 localhost 取决你 user 表里面Host 字段决定
E:\mysql\bin>mysql -uroot -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.21
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> use mysql
Database changed
mysql> select user,host from user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
mysql> alter user root@localhost identified by 'yourpassword';
Query OK, 0 rows affected (0.02 sec)
注意 修改完成后 需要重新开一个命令提示行窗口 以管理员身份运行 可以使用新密码进行操作
6.重新登录MYSQL 使用新密码
E:\mysql\bin>mysql -uroot -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.21 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>
-- 刘轶鹤