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

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

# mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS 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 -p2.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

转载于:https://www.cnblogs.com/keithtt/p/6922378.html

Mariadb修改root密码相关推荐

  1. mariadb数据库修改root密码

    mariadb数据库修改root密码 方法1 1.直接在shell命令行使用 mysqladm 命令修改. mysqladmin -uroot -poldpassword password newpa ...

  2. mysql 8 修改root密码忘记_忘记mysql8或者mariadb5及以上 的root密码如何更改

    实验环境 操作系统:lsb_release -a No LSB modules are available. Distributor ID:Ubuntu Description:Ubuntu 20.0 ...

  3. 阿里云 mysql 修改root密码修改_怎样修改数据库root密码

    在 Linux 中修改 MySQL 或 MariaDB 的 Root 密码 如果你是第一次安装 MySQL 或 MariaDB,你可以执行 mysql_secure_installation 脚本来实 ...

  4. centos的mysql修改root密码_CentOS环境中MySQL修改root密码方法

    环境相关: OS:CentOS release 6.9 IP:192.168.1.10 MySQL:MariaDB-10.1.30 1. 修改前的确认 修改root密码是需要重启mysql库,确认生产 ...

  5. MySQL修改root密码的方法、常见问题及解决方法

    文章目录 MySQL修改root密码的方法 知道密码的情况 1.使用ALTER USER命令修改密码 2.使用SET PASSWORD命令修改密码 忘记密码的情况 使用--init-file 使用-- ...

  6. linux新装mysql修改root密码_linuxmysql修改root密码

    一.如果2113知道root密码,5261只是更换mysql的root密码,可以通4102过mysqladmin来进行修改.执行如下命令:1653sudo mysqladmin -u root -p  ...

  7. fedora mysql默认密码忘记_Linux fedora 24 忘记密码图形化界面修改root密码的方法

    方法及其简单,只需要两步即可: 1.第一步: 打开终端,输入sudo su命令. –此处的密码为普通用户的密码,也就是开机时输入的密码. 2.第二步: 直接sudo passwd root就重置了ro ...

  8. mysql 5.7 修改root 密码

    前言 MySQL5.7为了加强安全性,yum 安装后为root用户随机生成了一个密码,同时修改root密码上,也增加了一些校验,会报 Your password does not satisfy th ...

  9. linux 进入单用户模式修改root密码

    Redhat系统Root密码的修改 一台双系统的机器,忘记redhat 的root密码了.    一.相关方法如下: 1. 开机在出现grub画面,按e键 2. 用上下键选中第二项(类似于kernel ...

最新文章

  1. spark 获取广播变量_Spark流式程序中广播变量和累加器为何使用单例模式
  2. 后台工具screen
  3. 通信原理之IP协议,ARP协议 (三)
  4. 你可能从未听过的 Linux 发行版
  5. Spring事务配置实例
  6. 如何把一个bin文件捆绑到一个可执行文件exe中?
  7. php正则匹配sg-nc-wap_PHP正则表达式匹配关键字之外HTML标签a
  8. 实际开发中的问题积累【积累】
  9. lambda函数if_现代 C++:Lambda 表达式
  10. paip.python 执行shell 带空格命令行attilax总结
  11. 基于flowplayer的视频缩略图的视频预览
  12. [奥塔在线]IIS Express如何开启HTPPS访问
  13. java h5在线音频_H5 录音音频可视化
  14. 《InnoDB存储引擎》第五章——索引与算法
  15. C语言的 a, *a, a
  16. redis的多路复用
  17. EV: 汽车驾驶技术与技巧
  18. 基于visual c++之windows核心编程代码分析(36)实践SYN安全隐患监测
  19. 好程序员web前端教程分享网页设计需要学那些东西?
  20. Qt/C++ 定时关机-给女票用的

热门文章

  1. 单机编程c语言,完美的8051单机C语言编程模板.doc
  2. ArchiCAD 23中文版
  3. Color Pilot 5中文版
  4. 【linux系统】maven安装
  5. Zend_Db_Table详解
  6. oc40--类的启动过程
  7. js/jq判断鼠标滚轮方向
  8. 记一次Redis和NetMQ的测试
  9. 首记,一种新的企业信息化平台开发方案——AgileEAS.NET框架
  10. 关于 MSDTC 分布式事务两个常见错误