错误一:
如果出现MySQL:由于找不到VCRUNTIME140_1.dll,无法继续执行代码。重新安装程序可能会解决此问题
错误二:
[ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
[ERROR] [MY-013236] [Server] The designated data directory E:\MySql\mysql-8.0.22-winx64\MySqlData\ is unusable. You can remove all files that the server added to it.
[ERROR] [MY-010119] [Server] Aborting
MySQL 服务正在启动 …
MySQL 服务无法启动。
服务没有报告任何错误。
请键入 NET HELPMSG 3534 以获得更多的帮助。
官网下载:https://dev.mysql.com/downloads/mysql/
下载后解压
新建文件my.ini内容为
[mysqld]
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=E:\\MySql\mysql-8.0.22-winx64
# 设置mysql数据库的数据的存放目录
datadir=E:\\MySql\mysql-8.0.22-winx64\\data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
default_authentication_plugin=mysql_native_password
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
port=3306
default-character-set=utf8
管理员模式下打开命令行cmd进入安装目录
使用mysqld -install进行安装
如果出现MySQL:由于找不到VCRUNTIME140_1.dll,无法继续执行代码。重新安装程序可能会解决此问题
安装这个微软常用运行库合集(https://www.repaik.com/),解决了
链接:https://pan.baidu.com/s/1r4JJaUKjw-y1g3lXZgKQ1g
提取码:f52r
使用命令mysqld --initialize-insecure成功后,会生成data目录并生成root用户, 输入启动命令: net start mysql。
如果出现
MySQL 服务正在启动 …
MySQL 服务无法启动。
服务没有报告任何错误。
请键入 NET HELPMSG 3534 以获得更多的帮助。
修改下面两行格式和上面一致
注意单斜杠和双斜杠
basedir=E:\\MySql\mysql-8.0.22-winx64
datadir=E:\\MySql\mysql-8.0.22-winx64\\data
mysqld --initialize --console查看错误信息
E:\MySql\mysql-8.0.22-winx64\bin>mysqld --initialize --console
2022-09-12T12:47:52.054999Z 0 [System] [MY-013169] [Server] E:\MySql\mysql-8.0.22-winx64\bin\mysqld.exe (mysqld 8.0.22) initializing of server in progress as process 14944
2022-09-12T12:47:52.055886Z 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-09-12T12:47:52.056552Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2022-09-12T12:47:52.056559Z 0 [ERROR] [MY-013236] [Server] The designated data directory E:\MySql\mysql-8.0.22-winx64\MySqlData\ is unusable. You can remove all files that the server added to it.
2022-09-12T12:47:52.058214Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-09-12T12:47:52.058653Z 0 [System] [MY-010910] [Server] E:\MySql\mysql-8.0.22-winx64\bin\mysqld.exe: Shutdown complete (mysqld 8.0.22) MySQL Community Server - GPL.
输入mysql -u root -p命令进入MySQL:提示输入密码直接回车
输入ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘123456’;修改密码
刷新MySQL的系统权限相关表
输入flush privileges;刷新MySQL系统权限相关表
前两种修改密码的方式有点问题在这里
mysql> set password for root@localhost = password('123456');
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 'password('123456')' at line 1
mysql> update user set authentication_string=password('123456') where user='root';
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 '('123456') where user='root'' at line 1
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'
-> ;
Query OK, 0 rows affected (0.19 sec)
mysql> **flush privileges
-> ;
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 '**flush privileges' at line 1
mysql> flush privileges;
Query OK, 0 rows affected (1.80 sec)
使用exit退出
再次进入MySQL
E:\MySql\mysql-8.0.22-winx64\bin>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
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>
在系统变量中配置环境变量
MYSQL_HOME
%MYSQL_HOME%\bin