MySQL修改root账号密码
MySQL数据库中如何修改root用户的密码呢?下面总结了修改root用户密码的一些方法
1: 使用set password语句修改
mysql> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.08 sec)
mysql> set password=password('123456');
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
2: 更新mysql数据库的user表
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> update user set password=PASSWORD('QwE123') where user='root';
Query OK, 4 rows affected (0.03 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
3:使用mysqladmin命令修改
命令一般为 mysqladmin -u root -p'oldpassword' password newpass 如下所示:
[root@DB-Server ~]# mysqladmin -u root -p'123456' password 'Qwe123'
Warning: Using a password on the command line interface can be insecure.
验证root密码修改是否成功
[root@DB-Server ~]# mysql -u root -p'Qwe123' -e 'show databases';
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
上面都是在知道root密码的情况下修改root密码,如果忘记了root密码,如何修改root的密码呢?
1:首先停掉MySQL服务
[root@DB-Server ~]# service mysql stop
Shutting down MySQL..[ OK ]
[root@DB-Server ~]#
或
[root@DB-Server ~]# /etc/rc.d/init.d/mysql stop
Shutting down MySQL..[ OK ]
2:然后使用mysqld_safe命令启动mysql,更新root账号的密码
--skip-grant-tables:不启动grant-tables(授权表),跳过权限控制。
--skip-networking :跳过TCP/IP协议,只在本机访问(这个选项不是必须的。可以不用)是可以不用
[root@DB-Server ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 5145
You have new mail in /var/spool/mail/root
[root@DB-Server ~]# 150709 14:10:53 mysqld_safe Logging to '/var/lib/mysql/DB-Server.localdomain.err'.
150709 14:10:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[root@DB-Server ~]# mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.20-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)
Copyright (c) 2000, 2014, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql
Database changed
mysql> UPDATE user SET password=PASSWORD("Qwe123") WHERE user='root';
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
3:重新启动MySQL服务。
MySQL修改root账号密码的更多相关文章
- debian官网qcow2镜像修改root账号密码,开启ssh等
1.下载官网qcow2镜像文件 wget http://172.16.20.10/vmtemplate/KVM/wangrui/Debian/debian-10.2.0-openstack-amd64 ...
- centOS7忘记密码,修改root账号密码
centOS7忘记密码,修改root账号密码 RHEL7 的世界发生了变化,重置 root 密码的方式也一样.虽然中断引导过程的旧方法(init=/bin/bash)仍然有效,但它不再是推荐的.“Sy ...
- 简单修改 MySQL 的 root 账号密码
首先这是一篇非常非常初级的教程. 平时为了方便,经常是直接在网上下载 PHP + MySQL 的集成环境,但有一些 MySQL 的 root 账号是没有密码的(例如大名鼎鼎的 XAMPP 就是这样), ...
- mac 安装mysql + 修改root用户密码 + 及报Access denied for user 'root'@'localhost' (using password:YES)解决办法
1.下载MySQL 到mysql的官网http://dev.mysql.com/downloads/mysql/然后在页面中会看到“MySQL Community Server”下方有一个“downl ...
- Mysql修改root用户密码 For Mac 报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
环境 Mysql版本:5.7.12 操作系统:OSX 10.11 安装文件:.dmg文件 MySQL:mysql-5.7.12-osx10.11-x86_64.dmg(注意5.7跟之前的字段有些不同, ...
- mysql 修改root登录密码
mysql -u root -p 然后回车,进入(等于用空密码进入) 2 use mysql; update user set password=password('123456') where us ...
- mysql修改root用户密码
自我总结,欢迎拍砖! 目的:若root用户密码忘记,则需要重新设置root用户的密码. 步骤: 1.找到mysql安装目录下的 my.ini 文件,找到[mysqlId]一行,在下方添加语句:skip ...
- 【Mysql】Mysql修改Root密码
1.用命令编辑/etc/my.cnf配置文件,即:vim /etc/my.cnf 或者 vi /etc/my.cnf 或者 nano /etc/my.cnf 2.在[mysqld]下添加skip-gr ...
- mysql修改root密码和对连接授权
mysql修改root密码 首先 mysql -uroot -p 进入mysql界面后执行 set password for root@localhost = password('111111'); ...
随机推荐
- 1Z0-053 争议题目解析685
1Z0-053 争议题目解析685 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 685.In your test database: -You are using Recover ...
- hibernate笔记--单向多对一映射方法
假设我们要建两张表,学生信息表(student)和年级信息表(grade),关系是这样的: 我们可以看出学生表和=年级表是多对一的关系,多个学生会隶属于一个班级,这种关系在hibernate中成为单边 ...
- JSP自定义tag
前端需要调用后端的配置,想起velocity-tools.然而jsp的话,目前只能想到tag和EL表达式了. Tag相当好写,jsp2.0提供了简化写法: 编写一个java类: public clas ...
- 如何设置 Panorama 控件的只读 SelectedIndex 属性?
在 OnNavigatedTo() 方法中设置: panoramaControl.DefaultItem = panoramaControl.Items[indexToSet];
- 【C#】DataRowState演变备忘
环境:.net 2.0 DataRow的行状态一段时间不用就会吃不准,记录一下,备查. DataRowState 演变表 行属于如下状态时进行右边操作→ 后的状态演变 添加到表 dt.Rows.Add ...
- Android ViewPager滑动背景渐变
原理 总 布局为RelativeLayout或者FrameLayout,在这里我们用的是RelativeLayout.先设置背景图片,宽度和高度都 fill_parent,在设置viewpager,v ...
- C# DataGridView中指定的单元格不能编辑
注意:DataGridView控件是从.NET Framework 2.0版本开始追加的. ReadOnly属性的使用 DataGridView内所有的单元格不能编辑 当DataGridView.Re ...
- js补充小知识点(continue,break,ruturn)
1.continue,break,ruturn eg:1-100的和 $(function () { $("#hello").click(function () { var iNu ...
- 【C#公共帮助类】DateTimeHelper设置电脑本地时间,实际开发很需要
关于本文档的说明 本文档主要为了解决实际开发当中,服务器和客户端电脑时间不能相等的问题,纯干货,实际项目这种时间不同步的情况很多很多,时间不相等,到时候把本地的数据提交给服务器,服务器看实际上传时间和 ...
- CAST function should support INT synonym for SIGNED. i.e. CAST(y AS INT)
Login / Register Developer Zone Bugs Home Report a bug Statistics Advanced search Saved searches T ...

