概述
本文参考了:https://www.pianshen.com/article/7287279782/
一、关闭SQL
第一种方法:
windows键+r,输入services.msc,点确定,如下所示
再找到MYSQL右键停止服务,
第二种方法:
如下所示用管理员身份打开命令行
cmd命令行输入:net stop mysql; 服务停止中 -> 服务已停止,如下所示
二、打开cmd界面,定位到mysql安装目录的bin文件下
也就是找到这个目录的里面的bin,里面放的是mysql.exe及mysqld.exe等,:
输入
cd C:Program Files (x86)MySQLMySQL Server 5.5bin
(注:地址是你自己的安装目录地址)
三、启动MySQL服务的时候跳过权限表认证
很多博主是输入“mysqld --skip-grant-tables ”,但是最新的数据库版本这个命令已失效,会发现命令窗口仍然跳出下一行待输入指令。
应该输入:
mysqld --console --skip-grant-tables --shared-memory
生成界面如下,此时dos窗口不能运行,再另开一个cmd窗口操作第四步。【我之前一直以为这样的是错误的界面,然而还是太天真了,其实这就是可以了,然后直接另开一个cmd去绕过修改mysql的密码的了。所以如果是下图这种情况,就可以直接去第四步了。】
注意:有可能会出现下图的情况
也就是这个InnoDB: The InnoDB memory heap is disabled错误情况。
这个错误的解决方法,就是在你的my.ini【Linux系统是my.cnf文件】里面的[mysqld]下面加一行
指代存放的地址空间到E盘的MySQL Datafiles,如果直接重启的话,文件夹会有如下情况:
如果还没有解决的话,就是找到你的存放数据库的data文件夹内,也就是根据你my.ini里面的datadir变量所指的路径我的是这个,如下图所示
删除掉下面三个文件:
>然后再重启mysql,基本上都能解决了。如果还不行,那我也没辙了,或者你可以下一下我待会上次的my.ini,是mysql5.5的,记得要改里面的basedir和datadir变量值就是了。
四、直接输入’mysql’免密登入数据库
输入 mysql,如果成功,显示如下界面,下一行的提示命令为mysql
五、输入’ use mysql '连接权限数据库
六、输入’ show tables; '(分号注意)
显示图片如下,最下面有一个user,里面就有我们想要的信息。
在这里插入图片描述
七、注意这里的第一种情况对应八的第一种情况处理,第二种情况对应八的第二种情况处理【我个人是属于第一种情况。】
**第一种情况输入:select user,host,password from user; 查看user信息如下图所示
如果提示错误ERROR 1054 (42S22): Unknown column ‘password’ in ‘field list’,就看第二种情况
第二种情况输入:select user,host from user; 查看user信息
八、修改密码
第一种情况(七中的第一种情况请按照这个来)
update user set password=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 ‘(‘123’) where user=‘root’ and host=‘localhost’’ at line 1
第二种情况(七中的第二种情况请按照这个来)
update mysql.user set authentication_string="123456" where user="root";
九、刷新权限。输入:flush privileges;(必做)
最后quit数据库,还会很萌地跟你say bye。
附加问题的解决方法:
ERROR 1130 (HY000): Host ‘127.0.0.1’ is not allowed to connect to this MySQL server
解决方法:注释掉my.ini中的skip_name_resolve
然后还有就是:查看数据库代码:
show databases;
通过命令行进入数据库代码:
mysql -u root -p
//回车,然后输入密码就可以了
写到现在这个博客,真的感慨万分,因为这次的东西是第二次遇见了,上一次也花了好长时间解决了,但是当时是好了伤疤忘了疼,没有写博客。而这次真的是十分地后悔,所以附上一个相对来说比较完整的解决方法吧,希望能够帮到大家!
再次声明:这篇博文参考了:https://www.pianshen.com/article/7287279782/
最后:
这是我my.ini文件的内容:
# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (using the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
server-id = 1
# Uncomment the following if you want to log updates
#log-bin=mysql-bin
# binary logging format - mixed recommended
#binlog_format=mixed
# Causes updates to non-transactional engines using statement format to be
# written directly to binary log. Before using this option make sure that
# there are no dependencies between transactional and non-transactional
# tables such as in the statement INSERT INTO t_myisam SELECT * FROM
# t_innodb; otherwise, slaves may diverge from the master.
#binlog_direct_non_transactional_updates=TRUE
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = C:\mysql\data\
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = C:\mysql\data\
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld]
innodb_use_sys_malloc =0
tmpdir = "E:\MySQL Datafiles"
#设置basedir指向mysql的安装路径
federated
skip-external-locking
#skip-name-resolve
basedir=C:Program Files (x86)MySQLMySQL Server 5.5
datadir=C:ProgramDataMySQLMySQL Server 5.5data
最后
以上就是英勇鞋垫为你收集整理的Mysql8.0数据库修改密码/无法修改密码【改用"mysqld --console --skip-grant-tables --shared-memory"修改密码】的全部内容,希望文章能够帮你解决Mysql8.0数据库修改密码/无法修改密码【改用"mysqld --console --skip-grant-tables --shared-memory"修改密码】所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复