Mariadb修改root密码
默认情况下,新安装的 mariadb 的密码为空,在shell终端直接输入 mysql 就能登陆数据库。
如果是刚安装第一次使用,请使用 mysql_secure_installation 命令初始化。
# 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 命令修改。
# mysqladmin -uroot -poldpassword password newpassword
这种方法的弊端在于会明文显示密码。
2、登陆数据库修改密码。
# 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、先停掉服务。
# systemctl stop mariadb
2、使用跳过授权的方式启动 mariadb。
# 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、当跳过授权启动时,可以不需要密码直接登陆数据库。登陆更新密码即可。
# mysql
MariaDB [(none)]> use mysql;
MariaDB [mysql]> UPDATE user SET password=password('newpassword') WHERE user='root';
MariaDB [mysql]> flush privileges;
MariaDB [mysql]> exit;
更新密码后,在跳过授权启动时也不能空密码直接登陆了。
4、关闭跳过授权启动的进程:
# kill -9 1441
5、正常启动 mariadb:
# systemctl start mariadb
Mariadb修改root密码的更多相关文章
- mariadb修改root密码的方法
mariadb安装好后,root密码为空,可以先使用HeidiSQL链接到数据库,执行以下sql,就可以修改root的密码了 update mysql.user set password=passwo ...
- Mariadb 修改root密码及跳过授权方式启动数据库
默认情况下,yum方式新安装的 mariadb 的密码为空,在shell终端直接输入 mysql 就能登陆数据库. 如果是刚安装第一次使用,请使用 mysql_secure_installation ...
- MariaDB忘记root密码
在MariaDB配置文件/etc/my.cnf [mysqld]中加入skip-grant-tables一行: [Richard@localhost ~]$ sudo vi /etc/my.cnf[ ...
- centos7 mariadb 设置root密码
centos7 mariadb 设置root密码 修改root密码1.以root身份在终端登陆,必须2.输入 mysqladmin -u root -p password root后面的 root ...
- Centos7 之 MariaDB(Mysql) root密码忘记的解决办法
MariaDB(Mysql) root密码忘记的解决办法 1.首先先关闭mariadb数据库的服务 # 关闭mariadb服务命令(mysql的话命令就是将mariadb换成mysql) [root@ ...
- CentOS忘记mariadb/mysql root密码解决办法
本文不再更新,可能存在内容过时的情况,实时更新请访问原地址:CentOS忘记mariadb/mysql root密码解决办法: 这里有两种方式实现修改mariadb root密码. mariadb版本 ...
- RedHat/Centos修改root密码
Linux主机忘记密码,只要你能接触物理主机都可以修改root密码的! Redhat6.x 5.x / Centos6.x 5.x 01.开机-空格/enter 02.e-编辑模式 CentO ...
- ansible非root用户批量修改root密码
前言: 由于线上服务器密码长久没有更新,现领导要求批量更换密码.线上的之前部署过salt,但由于各种因素没有正常使用. 使用自动化工具批量修改的计划搁浅了,后来领导给了个python多线程修改密码脚本 ...
- phpmyadmin修改root密码
很多人利用phpmyadmin或者命令行来修改了mysql的root密码,重启 后发现mysql登录错误,这是为什么呢?修改mysql的root的密码要在mysql软件中mysql数据库里修改root ...
随机推荐
- Android 解析标准的点击第三方文件管理器中的视频的intent
解析标准的第三方视频intent private List<String> mCurPlayList = new ArrayList<String>(); private in ...
- android Q build 变化
一 概述 android Q build变化整体上越来越严格,语法上之前能够使用的Q上将不能使用. 二 主要变化 2.1 'USER' 弃用 ‘USER’后面的值会被设置成‘nobody',andr ...
- Docker 创建 Jira Core(Jira SoftWare) 7.12.3 中文版
目录 目录 1.介绍 1.1.什么是 JIRA Core? 1.2.什么是 JIRA SoftWare 2.JIRA 的官网在哪里? 3.如何下载安装? 4.对 JIRA 进行配置 4.1.JIRA ...
- c/c++ 重载运算符 基本概念
重载运算符 基本概念 问题:对于int,float可以进行算数运算,但是对于一个自定义的类的对象进行算术运算,就不知道具体怎么运算了. 所以有了自定义运算符的概念. 1,自定义运算符其实就是一个以op ...
- 电信中兴F460光猫sendcmd命令
1.安装xshell后,使用命令行登陆root用户,root用户密码Zte521(湖北地区) 2.查看所有用户密码 sendcmd 1 DB p DevAuthInfo 3.打开网页登陆teleco ...
- LeetCode算法题-Fibonacci Number(Java实现)
这是悦乐书的第250次更新,第263篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第117题(顺位题号是509).Fibonacci数字,通常表示为F(n),形成一个称为 ...
- git冲突解决办法合集
一 换行符CRLF错误解决办法 1 错误产生原因 不同的操作系统使用的换行符是不一样的. unix/linux使用的是LF,max后期也采用了LF,但在windows一直采用的CRLF(回车)换行符. ...
- ios兼容 iphoneX ios10 ios11
假设你有一个固定位置的标题栏,你的iOS10的CSS可能是这样写的: header { position: fixed; top:; left:; right:; height: 44px; padd ...
- centos7下kubernetes(11。kubernetes-运行一次性任务)
容器按照持续运行的时间可以分为两类:服务类容器和工作类容器 服务类容器:持续提供服务 工作类容器:一次性任务,处理完后容器就退出 Deployment,replicaset和daemonset都用于管 ...
- python3 Counter模块
from collections import Counter c = Counter("周周周周都方法及")print(c)print(type(c))print('__iter ...