如何更改mysql登陆用户名密码

如何更改mysql登陆用户名密码,第1张

方法如下:

设备:华为笔记本。

系统:win7。

软件:mysql。

版本:8.0.11。

1、以管理员的身份打开cmd,然后跳过权限启动mysql,命令:xxx --skip-grant-tables 前面是mysql配置文件的位置,然后回车。

2、新打开个cmd窗口,进入到mysql配置文件目录bin下,然后输入 mysql -uroot -p 再回车,这步是以空密码进入mysql。

3、空密码进入mysql后,如果前面都设置正确的话,这步显示的界面是Welcome to the MariaDB monitor。

4、然后可以show database; 查看当前的数据库,回车后会列举出当前数据库的列表。

5、然后执行命令:update user set password=password('新密码') where user='root'并回车,其中括号中的就是将要设置的新密码。

6、执行完后会提示你 Query OK,表示执行成功了,再用新密码登录就可以了。

方法1: 用SET PASSWORD命令

首先登录MySQL。

格式:mysql>set password for 用户名@localhost = password(‘新密码’)

例子:mysql>set password for root@localhost = password(‘123’)

方法2:用mysqladmin

格式:mysqladmin -u用户名 -p旧密码 password 新密码

例子:mysqladmin -uroot -p123456 password 123

方法3:用UPDATE直接编辑user表

首先登录MySQL。

mysql>use mysql

mysql>update user set password=password(‘123’) where user=’root’ and host=’localhost’

mysql>flush privileges

方法4:在忘记root密码的时候,可以这样

以windows为例:

想知道linux下怎么修改密码吗?下面由我为大家整理了linux mysql修改密码命令,希望大家喜欢!

   linux mysql修改密码命令

   1.修改root密码

linux mysql修改密码命令方法1:使用mysqladmin命令

--适用于记得root旧密码,修改root密码

语法:

mysqladmin -u用户名 -p旧密码 password 新密码

例如:

# mysqladmin -u root -proot password mysql

--注意:如当旧密码输入错误时会报如下错误

# mysqladmin -u root -proot1 password mysql

mysqladmin: connect to server at 'localhost' failed

error: 'Access denied for user 'root'@'localhost' (using password: YES)'

linux mysql修改密码命令方法2:直接更新user表password字段

--适用于忘记root密码,而对root密码进行重置

Step 1: 修改MySQL的登录设置

# vi /etc/my.cnf

--windows系统是my.ini文件

--在[mysqld]的段中加上一句:skip-grant-tables,如没有[mysqld]字段,可手动添加上

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

skip-name-resolve

skip-grant-tables

Step 2: 重新启动mysql

[root@gc ~]# service mysql restart

Shutting down MySQL..[确定]

Starting MySQL...[确定]

Step 3: 登录并修改MySQL的root密码

--此时直接用mysql即可无需密码即可进入数据库了

[root@gc ~]# mysql

Welcome to the MySQL monitor. Commands end with or \g.

Your MySQL connection id is 2

Server version: 5.5.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, 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

Database changed

mysql>update user set password=password('new_password') where user='root'

Query OK, 5 rows affected (0.00 sec)

Rows matched: 5 Changed: 5 Warnings: 0

mysql>flush privileges

Query OK, 0 rows affected (0.00 sec)

--注意:如果没做step1,直接用mysql登录时会报如下错误

[root@gc ~]# mysql

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

Step 4: 将MySQL的登录设置修改回来

再删除/etc/my.cnf文件中的skip-grant-tables

Step 5: 重新启动mysql

[root@gc ~]# service mysql restart

Shutting down MySQL..[确定]

Starting MySQL...[确定]

   2.修改mysql其它用户密码

同样,普通用户也可以用上面的方法

--使用mysqladmin命令

[root@njdyw ~]# mysqladmin -u user1 -ppass1 password pass2

--直接修改数据库表

[root@njdyw ~]# mysql -u user1 -ppass1 –Dmysql

mysql>update user set password=password('pass2') where user='user1'

mysql>flush privileges


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5919727.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-08
下一篇 2023-03-08

发表评论

登录后才能评论

评论列表(0条)

保存