Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Mariadb修改root密码

Mariadb修改root密码

作者头像
botkenni
发布于 2019-09-03 08:02:31
发布于 2019-09-03 08:02:31
14.5K00
代码可运行
举报
文章被收录于专栏:IT码农IT码农
运行总次数:0
代码可运行

默认情况下,新安装的 mariadb 的密码为空,在shell终端直接输入 mysql 就能登陆数据库

如果是刚安装第一次使用,请使用 mysql_secure_installation 命令初始化。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

这里针对的是知道 root 密码,而需要修改的情况。

两种修改方法:

1、直接在shell命令行使用 mysqladm 命令修改。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# mysqladmin -uroot -poldpassword password newpassword

这种方法的弊端在于会明文显示密码。

2、登陆数据库修改密码。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# mysql -uroot -p

2.1 更新 mysql 库中 user 表的字段:
MariaDB [(none)]> use mysql;  
MariaDB [mysql]> UPDATE user SET password=password('newpassword') WHERE user='root';  
MariaDB [mysql]> flush privileges;  
MariaDB [mysql]> exit;

2.2 或者,使用 set 指令设置root密码:
MariaDB [(none)]> SET password for 'root'@'localhost'=password('newpassword');  
MariaDB [(none)]> exit; 

如果是忘记了 root 密码,则需要以跳过授权的方式启动 mariadb 来修改密码。

1、先停掉服务。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# systemctl stop mariadb

2、使用跳过授权的方式启动 mariadb。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# mysqld_safe --skip-grant-tables &
[1] 1441
[root@centos7 ~]# 170531 02:10:28 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
170531 02:10:28 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

# ps -ef | grep 1441
root      1441   966  0 02:10 pts/0    00:00:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables
mysql     1584  1441  0 02:10 pts/0    00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock

3、当跳过授权启动时,可以不需要密码直接登陆数据库。登陆更新密码即可。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# mysql
MariaDB [(none)]> use mysql;  
MariaDB [mysql]> UPDATE user SET password=password('newpassword') WHERE user='root';  
MariaDB [mysql]> flush privileges;   
MariaDB [mysql]> exit; 

更新密码后,在跳过授权启动时也不能空密码直接登陆了。

4、关闭跳过授权启动的进程:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# kill -9 1441 

5、正常启动 mariadb:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# systemctl start mariadb

G

M

T

Detect languageAfrikaansAlbanianArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChinese (Simplified)Chinese (Traditional)CroatianCzechDanishDutchEnglishEsperantoEstonianFilipinoFinnishFrenchGalicianGeorgianGermanGreekGujaratiHaitian CreoleHausaHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneseJavaneseKannadaKazakhKhmerKoreanLaoLatinLatvianLithuanianMacedonianMalagasyMalayMalayalamMalteseMaoriMarathiMongolianMyanmar (Burmese)NepaliNorwegianPersianPolishPortuguesePunjabiRomanianRussianSerbianSesothoSinhalaSlovakSlovenianSomaliSpanishSundaneseSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameseWelshYiddishYorubaZulu

AfrikaansAlbanianArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChinese (Simplified)Chinese (Traditional)CroatianCzechDanishDutchEnglishEsperantoEstonianFilipinoFinnishFrenchGalicianGeorgianGermanGreekGujaratiHaitian CreoleHausaHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneseJavaneseKannadaKazakhKhmerKoreanLaoLatinLatvianLithuanianMacedonianMalagasyMalayMalayalamMalteseMaoriMarathiMongolianMyanmar (Burmese)NepaliNorwegianPersianPolishPortuguesePunjabiRomanianRussianSerbianSesothoSinhalaSlovakSlovenianSomaliSpanishSundaneseSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameseWelshYiddishYorubaZulu

Text-to-speech function is limited to 200 characters

Options : History : Feedback : Donate

Close

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
MySQL root密码忘记,原来还有更优雅的解法!
一直以来,对于MySQL root密码的忘记,以为只有一种解法-skip-grant-tables。
星哥玩云
2022/08/16
3240
MySQL重置root密码方法
MySQL有时候忘记了root密码是一件伤感的事。这里提供Windows 和 Linux 下的密码重置方法。
叫我可儿呀
2019/11/29
3.5K0
部署 Mariadb HA 环境
部署 keepalived 的主要作用是为 Mariadb 提供 vip,在2个 Mariadb 实例之间切换,不间断的提供服务。
jwangkun
2021/12/27
1K0
MariaDB Centos7 下安装MariaDB
rpm包为例,对于标准服务器安装,至少需要下载client,shared,serve文件(安装时如果少了,会有错误提示的
授客
2019/09/11
4K0
MariaDB Centos7 下安装MariaDB
(三)centos7下安装MariaDB 10.0/MySQL数据库
来自官网的包源 https://downloads.mariadb.org/mariadb/repositorie
botkenni
2019/09/03
7770
(三)centos7下安装MariaDB 10.0/MySQL数据库
MariaDB数据库安装完需要初始化操作
确认MariaDB数据库软件程序安装完毕并启动成功后请不要立即使用,为了确保数据库的安全性和正常运转,咱们需要先进行对数据库程序初始化操作。
菲宇
2022/12/02
1.9K0
Centos6下使用yum安装MariaDB
1)增加mariaDB的yum源 [root@centos6-test08 ~]# cd /etc/yum.repos.d/ [root@centos6-test08 yum.repos.d]# cp CentOS-Base.repo CentOS-Base.repo.bak [root@centos6-test08 yum.repos.d]# vim CentOS-Base.repo ...... [mariadb] name = MariaDB baseurl = http://yum.mari
洗尽了浮华
2018/03/28
7420
Ubuntu 修改 mysql 密码
今天重置 mysql 密码时,遇到两个坑,所以记录下来以后复习。 用 mysql --version 查看当前 sql 版本 mysql Ver 14.14 Distrib 5.7.22, for Linux (x86_64) using EditLine wrapper 关闭 mysql service mysql stop 跳过安全检查 /usr/bin/mysqld_safe --skip-grant-tables & 更改密码 这时候新开一个终端依次执行下列命令 mysql -u root us
ppjun
2018/09/05
4.7K0
Macbook通过brew安装mysql8.0
MySQL 8 是mysql的最新版本,它带来了许多改进和新特性,主要新增特性如下:
鳄鱼儿
2024/07/01
1.5K0
忘记MySQL/MariaDB root密码的解决方法
MySQL/MariaDB 的root 密码忘了,不知道改怎么办,下面是修改root 密码步骤。
星哥玩云
2022/08/18
1.1K0
MySQL 修改用户密码及重置root密码
    为数据库用户修改密码是DBA比较常见的工作之一。对于MySQL用户账户的密码修改,有几种不同的方式,推荐的方式使用加密函数来修改密码。本文主要描述了通过几种不同的方式来修改用户密码以及mysql root账户密码丢失(重置root密码)的处理方法。
Leshami
2018/08/13
4.7K0
CentOS7安装MariaDB的流程步骤
安装前需要彻底清除你的服务器计算机上原来安装过的mysql、maraidb的文件,不然会出现各种问题。 CentOS7安装MariaDB的流程步骤如下:
青山师
2023/05/05
1.3K0
Linux 安装配置MariaDB
[root@dbServer ~]# yum install -y mariadb mariadb-server 已加载插件:fastestmirror Loading mirror speeds from cached hostfile  * base: mirrors.aliyun.com  * extras: mirrors.aliyun.com  * updates: mirrors.aliyun.com ........  ----------------------------------------------------------------------------------------------------------------------- 总计                                                                                                                                         1.8 MB/s |  20 MB  00:00:11      Running transaction check Running transaction test Transaction test succeeded Running transaction   正在安装    : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                                                                       1/4   正在安装    : perl-DBD-MySQL-4.023-5.el7.x86_64                                                                                                                        2/4   正在安装    : 1:mariadb-5.5.52-1.el7.x86_64                                                                                                                            3/4   正在安装    : 1:mariadb-server-5.5.52-1.el7.x86_64                                                                                                                     4/4   验证中      : 1:mariadb-server-5.5.52-1.el7.x86_64                                                                                                                     1/4   验证中      : perl-DBD-MySQL-4.023-5.el7.x86_64                                                                                                                        2/4   验证中      : 1:mariadb-5.5.52-1.el7.x86_64                                                                                                                            3/4   验证中      : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                                                                       4/4 已安装:   mariadb.x86_64 1:5.5.52-1.el7                        
程裕强
2022/05/06
1.1K0
MySQL 重置 root 密码以及修改密码时报错password字段不存在
执行后报错  ERROR 1054(42S22) Unknown column ‘password’ in ‘field list’
全栈程序员站长
2022/07/19
2.2K0
MySQL 重置 root 密码以及修改密码时报错password字段不存在
CentOS下设置MySQL的root密码
CentOS刚装的MySQL一般需要重设MySQL密码,可以用以下方法重设。  方法一、  Js代码   # /etc/init.d/mysqld stop   # mysqld_safe --user=mysql --skip-grant-tables --skip-networking &   # mysql -u root mysql    mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';    my
庞小明
2018/03/07
3.2K0
Ubuntu上MySQL 5.7.25修改root密码
使用sudo apt install mysql-server方法安装的MySQL服务,安装之后没有临时密码的日志,想着直接修改root密码,但是尝试了很多网上的方法,但是都无法生效,包括
俗可耐
2019/04/04
4.2K0
mysql ERROR 2002 (HY000): '/tmp/mysql.sock' 问题解决
一直用的好好的,突然就不能用了, 然后在网上搜了一圈,什么改配置my.cnf, 什么改软连接啊,换用5.7版本,都用了一次,结论是都不对.
solate
2019/07/22
30.2K3
mysql/mariadb忘记root密码
根据您在系统上运行的mysql或maridb服务器版本,您需要使用不同的命令来恢复root密码。
剧终
2020/08/27
5.2K0
MacOs安装mysql与修改root密码
mysql-5.7.21-1-macos10.13-x86_64.dmg下载地址是
超蛋lhy
2018/08/31
3.3K0
MacOs安装mysql与修改root密码
Centos 6.x 安装配置MySQL
service mysqld start chkconfig mysqld on
程裕强
2022/05/06
3780
相关推荐
MySQL root密码忘记,原来还有更优雅的解法!
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验