linux下mysql5.7.12忘记密码

1 篇文章 0 订阅

一. 碰到问题

问题:mac上安装的mysql5.7.12,长时间不用,忘记密码,navicat连接时提示:
Access denied for user ‘root’@’localhost’ (using password: YES)

解决:重置密码

二. 重置密码详情:

2.1 关闭mysql服务

mac下可在系统偏好设置中关闭或在终端中使用kill强制关闭,进入root用户

xiaoxiangdeMacBook-Pro:bin root# ps -ef|grep mysql
   74   838     1   0 10:17AM ??         0:00.53 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid
    0  1124   814   0 10:36AM ttys000    0:00.00 grep mysql
xiaoxiangdeMacBook-Pro:bin root# kill -9 838
xiaoxiangdeMacBook-Pro:bin root# ps -ef|grep mysql
    0  1133   814   0 10:37AM ttys000    0:00.00 grep mysql
2.2 启动mysql的安全模式

命令:./mysqld_safe –user=root –skip-grant-tables –skip-networking &

xiaoxiangdeMacBook-Pro:bin root# pwd
/usr/local/mysql/bin
xiaoxiangdeMacBook-Pro:bin root# ./mysqld_safe --user=root --skip-grant-tables --skip-networking & 
[1] 1184
xiaoxiangdeMacBook-Pro:bin root# 2016-08-09T02:40:37.6NZ mysqld_safe Logging to '/usr/local/mysql/data/xiaoxiangdeMacBook-Pro.local.err'.
2016-08-09T02:40:37.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

xiaoxiangdeMacBook-Pro:bin root# ps -ef|grep mysql
    0  1184   814   0 10:40AM ttys000    0:00.02 /bin/sh ./mysqld_safe --user=root --skip-grant-tables --skip-networking
    0  1296  1184   0 10:40AM ttys000    0:00.25 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=root --skip-grant-tables --skip-networking --log-error=/usr/local/mysql/data/xiaoxiangdeMacBook-Pro.local.err --pid-file=/usr/local/mysql/data/xiaoxiangdeMacBook-Pro.local.pid
    0  1303   814   0 10:41AM ttys000    0:00.00 grep mysql
2.3 使用root用户免密码登陆mysql

命令:mysql -u root -p

xiaoxiangdeMacBook-Pro:bin root# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 56
Server version: 5.7.12 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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正常运行的情况下,输入mysql提示:
mysql command not found
遇上-bash: mysql: command not found,是因为/usr/local/bin目录下没有mysql,需要建立软链接:把mysql安装目录,比如/usr/local/mysql/bin/mysql,映射到/usr/local/bin目录下:

# cd /usr/local/bin
# ln -fs /usr/local/mysql/bin/mysql mysql

还有其它常用命令mysqladmin、mysqldump等不可用时候都可按用此方法解决。创建后可查看:

xiaoxiangdeMacBook-Pro:~ root# ls /usr/local/bin
bbdiff      idea        prl_convert prlcore2dmp prlsrvctl
bbedit      mysql       prl_disk_tool   prlctl
bbfind      mysqladmin  prl_perf_ctl    prlexec
2.4 选择使用mysql数据库
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> 
2.5 重置密码

查看当前密码,已加密的。注意mysql的版本不同,密码存储的字段不同,首先查看mysql版本是5.7.12,密码存储字段为authentication_string;

xiaoxiangdeMacBook-Pro:bin root# mysql --version
mysql  Ver 14.14 Distrib 5.7.12, for osx10.11 (x86_64) using  EditLine wrapper
mysql> select user,host,authentication_string from user where user="root";
+------+-----------+-------------------------------------------+
| user | host      | authentication_string                     |
+------+-----------+-------------------------------------------+
| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
+------+-----------+-------------------------------------------+
1 row in set (0.00 sec)

mysql> 

重置密码,并查看,刷新权限,并退出mysql

mysql> update user set authentication_string=password('123456') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> select user,host,authentication_string from user where user="root";
+------+-----------+-------------------------------------------+
| user | host      | authentication_string                     |
+------+-----------+-------------------------------------------+
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+-----------+-------------------------------------------+
1 row in set (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit;
2.6 退出安全模式
xiaoxiangdeMacBook-Pro:bin root# ps -ef|grep mysql
    0  1184   814   0 10:40AM ttys000    0:00.02 /bin/sh ./mysqld_safe --user=root --skip-grant-tables --skip-networking
    0  1296  1184   0 10:40AM ttys000    0:00.54 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=root --skip-grant-tables --skip-networking --log-error=/usr/local/mysql/data/xiaoxiangdeMacBook-Pro.local.err --pid-file=/usr/local/mysql/data/xiaoxiangdeMacBook-Pro.local.pid
    0  1755   814   0 10:57AM ttys000    0:00.00 grep mysql
xiaoxiangdeMacBook-Pro:bin root# kill -9 1184
xiaoxiangdeMacBook-Pro:bin root# kill -9 1296
xiaoxiangdeMacBook-Pro:bin root# ps -ef|grep mysql
    0  1781   814   0 10:58AM ttys000    0:00.00 grep mysql
2.7 重新启动mysql,重启不了可以先重启一下机器,用navicat连接成功


以上,有问题请留言

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要设置MySQL 8.0的端口号,你可以按照以下步骤进行操作: 1. 首先,打开my.cnf配置文件,可以使用vi命令进行编辑。 2. 在my.cnf文件中,找到并修改"port"参数的值,将其改为你想要设置的端口号。 3. 保存并退出my.cnf文件。 4. 重新加载防火墙策略,可以使用firewall-cmd --reload命令。 5. 确认端口号是否已被修改,可以使用show global variables like 'port'命令在MySQL数据库中查看。 需要注意的是,如果你使用的是MySQL 5.7.12及以上版本,并且安装了X插件,默认情况下MySQL会监听两个端口:12345和33060。如果你想禁用X插件,可以在my.cnf文件中添加mysqlx=0来关闭它。另外,你也可以在启动时使用--mysqlx=0或--skip-mysqlx参数来禁用X插件。 希望以上信息能够帮助到你,如果有任何问题,请随时留言交流学习!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [[MySQL]如何修改MySQL8.0端口(centos 7)](https://blog.csdn.net/m0_67394360/article/details/126553035)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [LinuxMysql8.0数据库修改端口号的教程(完整版)](https://blog.csdn.net/weixin_50093343/article/details/116589405)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值