mysql修改用户密码
修改自己的密码(root用户,其它用户应该也差不多)
方法一:
[root@localhost /]# mysqladmin -u root -p password "root" #修改密码为root
Enter password: #输入旧密码
[root@localhost /]# mysql -uroot -p #尝试使用旧密码登录
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@localhost /]# mysql -uroot -p #输入新密码root登录
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
方法二:
在mysql.user中使用update更新密码
方法三:
或者进入mysql后,使用set修改密码
[root@localhost /]# mysql -uroot -p #使用旧密码root登录
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> set password=password("123456"); #修改密码为123456,我一直很好奇为什么密码必须用password扩起来,后来知道了,新密码必须用password来加密
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit
Bye
[root@localhost /]# mysql -uroot -p #使用新密码123456登录
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 20
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
root用户修改指定用户密码
方法一
MariaDB [(none)]> set password for 'bp'@'localhost'=password("123456");
Query OK, 0 rows affected (0.01 sec)
方法二:
MariaDB [(none)]> update mysql.user set password=password("123") where user='bp' and host='localhost'; #使用update修改密码,修改成功后,我打开另一个终端使用该用户登录数据库,发现无法使用新密码登录,但使用旧密码可以登录
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [(none)]> select user,host from mysql.user; #因为报错信息里面包含localhost,于是查看用户表信息有没有错,遗憾的是没有
+---------+-----------------------+
| user | host |
+---------+-----------------------+
| aa | % |
| aaa | % |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| aa | localhost |
| bb | localhost |
| bp | localhost |
| ggo | localhost |
| my | localhost |
| mytest | localhost |
| newuser | localhost |
| nome | localhost |
| root | localhost |
| | localhost.localdomain |
| root | localhost.localdomain |
+---------+-----------------------+
16 rows in set (0.00 sec)
MariaDB [(none)]> flush privileges; #后来想起来,是不是还要刷新权限。刷新之后,使用新密码可以登录
Query OK, 0 rows affected (0.00 sec)
方法三:grant修改密码
MariaDB [mytest]> grant select on mytest.test to 'bp'@'localhost' identified by 'linux';
Query OK, 0 rows affected (0.05 sec) #这个不需要刷新权限。。
mysql5.7修改密码
cat /var/log/mysqld.log|grep 'temporary password'
alter user 'root'@'localhost' identified by 'root';
忘记密码(需要重启服务器)
在/etc/my.cnf的mysqld里面增加skip-grant-tables (5.7以前的应该是skip-grant)
重启mysqld
mysql> update mysql.user set authentication_string=password(',,,abc123...') where user='root'; (旧版的应该是update mysql.user set password=password(',,,abc123...') where user='root';)
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
重启服务器
mysql修改用户密码的更多相关文章
- MySQL——修改用户密码 | 移除权限
修改用户密码 '; 移除权限 REVOKE Delete, Drop ON *.* FROM `root`@`localhost`; 权限列表
- mysql 修改用户密码
修改mysql用户密码 目录 mysqladmin命令 UPDATE user 语句 SET PASSWORD 语句 root密码丢失的情况(待验证) mysqladmin命令(回目录) 格式如下 ...
- mysql修改用户密码 新增用户
修改密码: mysql> grant all privileges on *.* to yongfu_b@'192.168.1.%' identified by 'my_password_new ...
- Mysql—修改用户密码(重置密码)
1.登录mysql [root@localhost ~]# mysql -uroot -p123456 [root@localhost ~]# mysql -hlocalhost -uroot -p1 ...
- mysql修改用户密码笔记(转)
方法1: 用SET PASSWORD命令 首先登录MySQL. 格式:mysql> set password for 用户名@localhost = password('新密码'); 例子:my ...
- mysql修改用户密码的方法及命令
方法1: 用SET PASSWORD命令 首先登录MySQL. 格式:mysql> set password for 用户名@localhost = password('新密码'); 例子:my ...
- mysql修改用户密码命令
C:\Users\20160216>mysql -h 10.180.6.183 -u root -pEnter password: ******Welcome to the MySQL moni ...
- 详解MySQL的用户密码过期功能
这篇文章主要为大家详细介绍了MySQL的用户密码过期功能的相关资料,需要的朋友可以参考下 Payment Card Industry,即支付卡行业,PCI行业表示借记卡.信用卡.预付卡.电子钱包. ...
- mysql基础:登录退出,修改用户密码,添加删除用户
今天刚开始学习mysql,最先接触用户管理,给大家分享下 注:mysql中命令的大小写都可以的 ==========登录退出相关=================== root@jack-deskto ...
随机推荐
- Java 几种showMessageDialog的表示
最近在做swing程序中遇到使用消息提示框的,JOptionPane类其中封装了很多的方法. 很方便的,于是就简单的整理了一下. 1.1 showMessageDialog 显示一个带有OK 按钮的模 ...
- 每天CSS学习之letter-spacing
letter-spacing是CSS的一个属性,其作用是设置字符之间的距离.letter意为字符. 1.normal:规定字符之间没有额外的空间.该值是默认值.如下示例: p{ letter-spac ...
- react与vue的对比
模板: Vue Vue应用的默认选项是把markup放在HTML文件中. 数据绑定表达式采用的是和Angular相似的mustache语法,而指令(特殊的HTML属性)用来向模板添加功能. React ...
- 20165326 java第七周学习笔记
第七周学习笔记 MySQL(数据管理系统)学习 知识点总结: 不能通过关闭MySQL数据库服务器所占用的命令行窗口来关闭MySQL数据库. 如果MySQL服务器和MySQL管理工具驻留在同一台计算机上 ...
- socketserver 和 事件Event
socketserver 处理socket服务端 # 服务端TCP: import socketserver from threading import current_thread # fork l ...
- 并行【parallel】和并发【concurrency】线程是并发还是并行,进程是并发还是并行
线程是并发,进程是并行:进程之间相互独立,是系统分配资源的最小单位,同一个线程中的所有线程共享资源. 并行,同一时刻多个任务同时在运行. 并发,在同一时间内隔内多个任务都在运行,但是都不会在同一时刻同 ...
- reset.css 文件
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,b ...
- git clone新项目后如何拉取分支代码到本地
1.git clone git@git.n.xxx.com:xxx/xxx.git 2.git fetch origin dev 命令来把远程dev分支拉到本地 3.checkout -b de ...
- Spring Relational Database
为了避免持久化的逻辑分散到应用的各个组件中,将数据访问功能放到一个或多个专注于此项任务的组件中,这样的组件通常称为数据访问对象(DAO)或Repository. 为了避免应用与特定的数据访问策略耦合在 ...
- 如何在VMware中安装Linux系统
这篇文章主要讲述如何在VMware12中安装RHEL6.9Linux操作系统 步骤一: 打开VMware软件,在主页中点击创建新的虚拟机或者点击左上角文件,在列表中点击新建虚拟机,如图: 步骤二: 点 ...