参考:
[作者:在七楼](https://www.cnblogs.com/RayWang/p/9347874.html)
[作者:pycod](https://www.cnblogs.com/xuanbjut/p/10406980.html)
安装完mysql后我遇到了这两个令人烦恼到错误,闲来无事来整理一下解决办法
错误一
错误二
步骤一.mysql下载安装:
1.1链接:mysql官网链接
1.2.mysql下载步骤:
a.点击官网链接进入首页
b.下滑到官网底部,找到DOWNLOADS-MySQL Community Server,进入MySQL Community Server
c.找到适合自己的版本,下载安装
1.3.具体安装步骤这里不做讲述;
2.1.安装完mysql后还需要安装一个Navicat for MySQL或者SQLyog Enterprise
Navicat for MySQL下载步骤如下:
Navicat for MySQL下载链接
a1.进入官网首页,点击Download
a2.点击Download进行下载
a3.安装步骤在此不做讲述;
SQLyog Enterprise下载步骤如下:
SQLyog Enterprise下载l链接
b1.进入SQLyog Enterprise首页,点击Free Download
b2.点击Free Download下载安装
b3.安装步骤在此不做讲述;
步骤二 .在我满心欢喜,以为万事俱备的时候,就出现了开头的些错误。my gad!心中一万个f…
1.1好了我们先来解决第一个错误:
1.2.出现这个问题是我们的数据库mysql缺少文件data,my.ini
1.3.在官网下载解压后是没有data,以及my.ini文件的,需要自动生成data,以及自己新建一个my.ini文件。
1.4.首先我们先在mysql-8.0.20-winx64安装目录下新建一个my.ini文件,注意是my.ini文件而不是my.ini.txt文件
a1.用记事本打开my.ini文件并将以下代码粘贴至my.ini文件,
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_bin
init_connect='SET NAMES utf8mb4'
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = D:\my software\mysql\mysql-8.0.20-winx64
datadir =D:\my software\mysql\mysql-8.0.20-winx64\data
port = 3306
# server_id = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size = 128M
sort_buffer_size = 16M
read_rnd_buffer_size = 16M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
a2.修改basedir和datadir为自己的mysql安装位置并保存
1.5.以管理员的身份打开cmd,并切换至mysql的bin目录下
图一.以管理员的身份打开cmd
图2.切换至MySql的bin目录下,删除数据库MySql
D:\MySql\bin>sc delete MySql
图3. 重新生成data文件
D:\MySql\bin>mysqld --initialize-insecure --user=mysql
执行完这些代码你会发现,MySql安装目录下会生成一个data文件
图4. 重新安装mysql服务,同时绑定my.ini配置文件
D:\MySql\bin>mysqld --install "MySql" --defaults-file="d:/mysql/my.ini"
mysql设置为自己想设置的大小写名字,d:/mysql/my.ini换成自己的my.ini安装位置
图5.启动数据库,启动成功则数据库使用就不会出现ErrorNo.2003及10061错误了。
D:\MySql\bin>net start mysql
注意:如果启动失败则是my.ini文件设置有问题,修改my.ini,删除data文件从头再来
步骤三.如果你“运气”爆棚又遇到ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)或者ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)错误,那么请君静下心来继续往下看。
3.1出现access denied的原因有这些:
a.mysql的配置文件错误----my.ini等文件,上面已经解决。此处不再叙述。
b.mysql的服务器停止
解决:若MySQL已经没有启动,重启MySQL服务器:net start mysql
c.用户的端口号或者IP导致
解决:若用户的端口号与IP(3306/3307)不一致,打开my.ini文件进行编辑。全部编辑替换为: port=X
d.root用户的密码错误
解决办法:
d1.打开my.ini文件,在[mysqld]下添加skip-grant-tables
skip-grant-tables
d2.重启MySQL服务器。
net stop mysql
net start mysql
d3.登录mysql,键入mysql –uroot –p;直接回车(Enter)
mysql –uroot –p
d4.键入无效set password for ‘root’@‘localhost’=password(‘1234’);
set password for ‘root’@‘localhost’=password(‘1234’);
d5.再把my.ini的skip-grant-tables删除,然后重启MySQL服务器:net stop mysql ;net start mysql;同上;
d6.再次进行设置密码:使用set password for ‘root’@‘localhost’=password(‘1234’);或者ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘你的密码’;
在8.0之前的版本,修改root用户密码的命令是:
set password for ‘root’@‘localhost’=password(‘你的密码’);
或者
update mysql.user set authentication_string=password("你的密码") where user="root";
在8.0之后的版本,修改root用户密码的命令是:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
最后重启mysql数据库,net stop mysql /net start mysql,打开Navicat for MySQL或者SQLyog Enterprise看看是否能正常使用,
net stop mysql // net start mysql
作者: <%相遇既是缘分%>
出处:https://blog.csdn.net/New__Horizons/article/details/106242029
本站使用「CC BY 4.0」创作共享协议,转载请在文章明显位置注明作者及出处。