刚好最近本地环境需要用到MySQL,所以就去安装了下。本文对安装的过程遇到的几个问题记录下。


1、[ERROR] --initialize specified but the data directory has files in it. Aborting.

1.1、当使用MySQL压缩安装,执行命令

mysqld  --initialize

报如下错误:

D:\Program Files\MySQL\mysql-5.7.29-winx64\bin>mysqld  --initialize
2020-03-30T09:23:40.737469Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-03-30T09:23:40.737528Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2020-03-30T09:23:40.737533Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2020-03-30T09:23:40.739795Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2020-03-30T09:23:40.740519Z 0 [ERROR] Aborting

1.2、原因是原先的data目录下已有数据,只要将data目录删除,然后重新运行命令即可。

MySQL压缩包安装问题记录_数据库

运行成功如下:

D:\Program Files\MySQL\mysql-5.7.29-winx64\bin>mysqld  --initialize
D:\Program Files\MySQL\mysql-5.7.29-winx64\bin>


2、ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

D:\Program Files\MySQL\mysql-5.7.29-winx64\bin>mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

2.1、打开MySQL目录下的my.ini文件(Linux环境在 /etc/my.cnf)。

MySQL压缩包安装问题记录_mysql_02

2.2、在文件的[mysqld]后面最后添加一行“skip-grant-tables”,保存并关闭文件。

MySQL压缩包安装问题记录_数据库_03

2.3、重启MySQL57和MySQL Router服务。

net stop mysql
net start mysql

2.4、进入mysql,修改初始密码

默认账户是root  登录命令: mysql -u root -p  要求输入时直接回车键  切换数据库命令:use mysql;  修改密码命令:update user set authentication_string=password('123456') where user='root' and Host = 'localhost';  刷新数据库命令:flush privileges;  退出命令:quit;


3、mysql数据库在Navicat Premium连接的时候出现1862错误

MySQL压缩包安装问题记录_mysql_04

3.1、管理员权限运行命令:mysqladmin -uroot -p password

MySQL压缩包安装问题记录_数据库_05

设置新的密码之后,问题解决。