MySQL 案例实战--修改 MySQL 数据库的登录密码
发布日期:2021-06-28 20:05:38
浏览次数:2
分类:技术文章
本文共 3354 字,大约阅读时间需要 11 分钟。
修改 MySQL 数据库的登录密码
前言
本环境是基于 Centos 7.8 系统构建MySQL-5.7.14 具体构建,请参考
一、登录数据库
MySQL基础操作:
1、启动/关闭:systemctl start/stop mysqld.service 2、登录与退出 1)mysql命令行 mysql -u用户 -p密码 -h IP地址 -D数据库名 -P端口注意:-p密码 不能有空格,密码有特殊字符,需要用单引号括起来。
2) 退出 \q quit exit
登录据库
#获取初始密码[root@mysql-server ~]# awk '/temporary password/ {print $NF}' /var/log/mysqld.log O/Q-owypP9xl#登录数据库[root@mysql-server ~]# mysql -uroot -pO/Q-owypP9xl -h localhost -D test -P 3306mysql: [Warning] Using a password on the command line interface can be insecure.ERROR 1049 (42000): Unknown database 'test'[root@mysql-server ~]# mysql -uroot -pO/Q-owypP9xl -h localhost -D mysql -P 3306mysql: [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 4Server version: 5.7.14Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> mysql> alter user root@localhost identified by 'ABCabc123!'; mysql> select version();+-----------+| version() |+-----------+| 5.7.14 |+-----------+1 row in set (0.00 sec)mysql>
二、修改密码
1、命令行修改
空密码修改
[root@mysql-server ~]# mysqladmin -uroot password '123abcABC!'
非空密码修改
[root@mysql-server ~]# mysqladmin -uroot -p'ABCabc123!' password '123abcABC!'
2、alter user 方式修改
mysql> alter user root@localhost identified by 'abcABC123!';Query OK, 0 rows affected (0.00 sec)
3、set password for 方式修改
mysql> set password for 'root'@'localhost' = 'abc123ABC!';Query OK, 0 rows affected (0.00 sec)
4、更新用户表 mysql.user 方式修改
mysql> update mysql.user set authentication_string=password('123abcABC!!') -> where user='root' and host='localhost';Query OK, 1 row affected, 1 warning (0.10 sec)Rows matched: 1 Changed: 1 Warnings: 1mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)
三、重置密码
#跳过权限表[root@mysql-server ~]# mysqld --user=mysql --skip-grant-tables#登录数据库,修改密码[root@mysql-server ~]# mysqlWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.14 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> alter user root@localhost identified by 'ABCabc123!';Query OK, 0 rows affected (0.00 sec)mysql> #停止数据库[root@mysql-server ~]# killall mysqld#启动服务[root@mysql-server ~]# systemctl start mysqld#登录成功[root@mysql-server ~]# mysql -u root -p'ABCabc123!'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 2Server version: 5.7.14 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
转载地址:https://blog.csdn.net/XY0918ZWQ/article/details/109201622 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
表示我来过!
[***.240.166.169]2024年04月21日 16时15分55秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Windows账号类型区别
2019-04-29
论文管理工具梳理
2019-04-29
机场净空区
2019-04-29
Civil3D
2019-04-29
ceisum加载shp格式的城市白模建筑数据
2019-04-29
PuTTY使用方法
2019-04-29
Ubuntu中apache的使用
2019-04-29
WinSCP使用
2019-04-29
MeteoEarth全球天气
2019-04-29
OruxMaps
2019-04-29
mbtiles server 使用错误记录
2019-04-29
MapTiler介绍
2019-04-29
go语言安装及使用
2019-04-29
Go语言版的mbtileserver使用
2019-04-29
PortableBasemapServer(PBS)
2019-04-29
跨域访问问题原因
2019-04-29
MBUtil实现mbtiles文件和地图切片之间的格式转换
2019-04-29