Mariadb初始登陆报错 ERROR 1045 (28000) 的解决办法

本文涉及的产品
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
RDS MySQL DuckDB 分析主实例,基础系列 4核8GB
RDS AI 助手,专业版
简介:

  今天,测试环境下需要使用到mysql数据库;于是我使用yum安装方式快速部署了mariadb。使用的Linux系统版本为CentOS 7.x。 

  安装完成后,我很自然的使用mysql命令登陆,因为是刚安装的初始环境,结果报错了: 

1
2
[root@node ~] # mysql
ERROR 1045 (28000): Access denied  for  user  'root' @ 'localhost'  (using password: NO)

  第一次碰到这种情况。我检查了配置文件,没发现异常,另外yum安装,也是初始环境,应该不会有问题。无奈只能上网找找相关的案例试试。 

  还好,最后成功的解决了此问题。 

  解决步骤如下: 

1,首先停掉数据库服务: 

1
[root@node ~] # systemctl stop mariadb.service

2,使用mysqld_safe来启动mysqld服务器: 

1
2
3
4
[root@node ~] # mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 4120
[root@node ~] # 170301 11:04:57 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
170301 11:04:57 mysqld_safe Starting mysqld daemon with databases from  /var/lib/mysql

3,登录: 

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@node ~] # 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 MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection  id  is 1
Server version: 5.5.52-MariaDB MariaDB Server
 
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
 
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the current input statement.
 
MariaDB [mysql]>

4,修改root用户密码: 

1
2
3
4
5
6
7
8
9
10
MariaDB [mysql]> UPDATE user SET PASSWORD=PASSWORD( 'newpassword' ) where USER= 'root' ;
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0
 
MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [mysql]> QUIT
Bye
[root@node ~] #

5,使用修改后的root用户和新密码newpassword登录数据库: 

1
2
3
4
5
6
7
8
9
10
11
[root@node ~] # mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection  id  is 6
Server version: 5.5.52-MariaDB MariaDB Server
 
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
 
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the current input statement.
 
MariaDB [(none)]>


到此,该问题成功解决!

本文转自 羽丰1995 51CTO博客,原文链接:http://blog.51cto.com/13683137989/1902267


相关实践学习
自建数据库迁移到云数据库
本场景将引导您将网站的自建数据库平滑迁移至云数据库RDS。通过使用RDS,您可以获得稳定、可靠和安全的企业级数据库服务,可以更加专注于发展核心业务,无需过多担心数据库的管理和维护。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
相关文章
|
Oracle 关系型数据库 MySQL
centos6安装mariadb失败及解决办法
centos6安装mariadb失败及解决办法
612 4
|
缓存 关系型数据库 MySQL
error: Failed dependencies: mariadb-connector-c-config is obsoleted by mysql-community-server-8.0.36-1.el7.x86_64 问题解决
error: Failed dependencies: mariadb-connector-c-config is obsoleted by mysql-community-server-8.0.36-1.el7.x86_64 问题解决
1107 19
|
关系型数据库 MySQL 数据库
ERROR! MariaDB is running but PID file could not be found
在CentOS7.6上安装了MariaDB10.3,采用的yum方式安装的,用命令查看数据库的状态会报错误
312 0
QGS
|
监控 Oracle 网络协议
Navicat Premium 12远程登入Oracle,mariadb报错及处理方法
Navicat Premium 12远程登入Oracle报错及处理方法
QGS
253 0
|
NoSQL 关系型数据库 MySQL
阿里云RDS关系型数据库大全_MySQL版、PolarDB、PostgreSQL、SQL Server和MariaDB等
阿里云RDS关系型数据库如MySQL版、PolarDB、PostgreSQL、SQL Server和MariaDB等,NoSQL数据库如Redis、Tair、Lindorm和MongoDB
537 0
|
6月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
1156 152
|
6月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎,提供高性价比、稳定安全的云数据库服务,适用于多种行业与业务场景。
889 156
|
6月前
|
关系型数据库 分布式数据库 数据库
阿里云数据库收费价格:MySQL、PostgreSQL、SQL Server和MariaDB引擎费用整理
阿里云数据库提供多种类型,包括关系型与NoSQL,主流如PolarDB、RDS MySQL/PostgreSQL、Redis等。价格低至21元/月起,支持按需付费与优惠套餐,适用于各类应用场景。

推荐镜像

更多