时间:2023-10-27来源:系统城装机大师作者:佚名
通过登录mysql系统,
1 2 3 |
mysql -uroot -p Enter password : 【输入原来的密码】 mysql>use mysql; |
查看下自己mysql的版本,注意不同的版本修改密码的方式会有所不同
1 | mysql> select version(); |
根据自己的版本从下面的方式中,选择一种进行修改密码即可
5.7以前
1 | mysql> update user set password = password (“123456”) where user =‘root'; |
5.7版本 user表没有了password字段,要用authentication_string代替
1 | mysql> update user set authentication_string= password (“123456”) where user =‘root'; |
8.0以上版本 注意密码要有数字,大小写字母,和特殊符号,要不密码会验证不通过
1 | mysql> ALTER USER ‘root ' IDENTIFIED BY ‘123456@Test' ; |
刷新权限(必须步骤)
1 2 |
mysql> flush privileges ; mysql> exit; |
修改完后要记得重启下mysql服务,让修改生效
1 | service mysqld restart |
不知道mysql密码的情况下,在安全模式下启动mysql,不用输入密码就可以登录进去,&表示在后台运行,不再后台运行的话,就要再打开一个终端。
1 | mysqld_safe --skip-grant-tables & |
或者你可以
输入:vi /etc/my.cnf 回车。在这个文件中的最后一行输入:skip-grant-tables
然后重启mysql服务 service mysqld restart 进入到安全模式,修改完密码后记得再删除掉这行数据重启下
1 | mysql -uroot -p |
然后提示你输入原密码,安全模式下直接回车就可以进入mysql数据库了;
1 | mysql>use mysql; |
后面的步骤跟上面一样了,根据自己的版本选择修改方式
5.7以前
1 | mysql> update user set password = password (“123456”) where user =‘root'; |
5.7版本 user表没有了password字段,要用authentication_string代替
1 | mysql> update user set authentication_string= password (“123456”) where user =‘root'; |
8.0以上版本 注意密码要有数字,大小写字母,和特殊符号,要不密码会验证不通过
1 | mysql> ALTER USER ‘root ' IDENTIFIED BY ‘123456@Test' ; |
刷新权限(必须步骤)
1 2 |
mysql> flush privileges ; mysql> exit; |
修改完后要记得重启下mysql服务,让修改生效
1 | service mysqld restart |
本意向修改一个用户的密码,网上搜到的命令为如下
1 | mysql> update user set password = password (“新密码”) where user =”用户名”; |
执行后报错:
ERROR 1054(42S22) Unknown column 'password' in ‘field list’
错误的原因是 5.7版本下的mysql数据库下已经没有password这个字段了,password字段改成了authentication_string
所以请使用一下命令:
E:\app\mysql\mysql-5.7.22-winx64\bin>mysql -uroot -pmysql123 # 先进入数据库
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.22 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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> use mysql; # 使用mysql
Database changed
mysql> select User from user; # 此处为查询用户命令
+---------------+
| User |
+---------------+
| root |
| root |
| mysql.session |
| mysql.sys |
| root |
+---------------+
5 rows in set (0.01 sec)
mysql> update mysql.user set authentication_string=password('mysql') where user='root'; # 更新密码
Query OK, 3 rows affected, 1 warning (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 1
mysql> flush privileges; # 数据刷新
Query OK, 0 rows affected (0.00 sec)
mysql> quit # 退出
Bye
E:\app\mysql\mysql-5.7.22-winx64\bin>mysql -uroot -pmysql # 再次进入
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.22 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
跟我这样设置,就可以了,大家自己设置自己的密码就行
2023-10-27
MySQL恢复误删数据图文教程2023-10-27
MySQL ibdata1文件减肥过程解析2023-10-27
mysql5.7中的密码忘记如何找回一、Mysql中数值类型下图为Mysql支持的数值类型及取值范围 BIT[M] 位字段类型,M表示每个值的位数,范围从1到64,如果M被忽略,默认为1 TINYINT[(M)] [UNSIGNED] [ZEROFILL] M默认...
2023-10-27
mysql之count()和sum()用法及区别1、mysql 数据库中 count() 函数是统计查询结果中的行数,例如我们有下表 user_auth :使用 count() 函数来查询结果个数,使用如下查询: 1 ...
2023-10-27