阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

136次阅读
没有评论

共计 2470 个字符,预计需要花费 7 分钟才能阅读完成。

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

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

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

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

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

解决步骤如下:

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

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

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

[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, 登录:

[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 用户密码:

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 登录数据库:

[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)]>

到此,该问题成功解决!

Ubuntu 16.04 LTS 上安装 Nginx、MariaDB 和 HHVM 运行 WordPress  http://www.linuxidc.com/Linux/2016-10/136435.htm

Ubuntu 16.04 Dockerfile 安装 MariaDB  http://www.linuxidc.com/Linux/2016-09/135260.htm

Linux 系统教程:如何检查 MariaDB 服务端版本  http://www.linuxidc.com/Linux/2015-08/122382.htm

MariaDB Proxy 读写分离的实现 http://www.linuxidc.com/Linux/2014-05/101306.htm

Linux 下编译安装配置 MariaDB 数据库的方法 http://www.linuxidc.com/Linux/2014-11/109049.htm

CentOS 系统使用 yum 安装 MariaDB 数据库 http://www.linuxidc.com/Linux/2014-11/109048.htm

二进制安装 MariaDB 5.5.36 http://www.linuxidc.com/Linux/2017-02/140233.htm

Ubuntu 上如何将 MySQL 5.5 数据库迁移到 MariaDB 10  http://www.linuxidc.com/Linux/2014-11/109471.htm

[翻译]Ubuntu 14.04 (Trusty) Server 安装 MariaDB  http://www.linuxidc.com/Linux/2014-12/110048htm

Ubuntu 14.04(Trusty) 安装 MariaDB 10 数据库  http://www.linuxidc.com/Linux/2016-11/136833.htm

MariaDB 的详细介绍 :请点这里
MariaDB 的下载地址 :请点这里

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-03/141240.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计2470字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中