MySQL登录报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

环境:CentOS 6.5 64bit

一、安装mysqld(mysql-server)

查看系统中是否已经安装mysqld

[root@localhost ~]# rpm -e mysql-server
error: package mysql-server is not installed

先通过如下命令查看yum上提供下载的mysql版本信息

[root@localhost ~]# yum list | grep mysql
mysql-libs.x86_64                            5.1.73-8.el6_8              @base
php-mysql.x86_64                             5.3.3-49.el6                @base
apr-util-mysql.x86_64                        1.3.9-3.el6_0.1             base
bacula-director-mysql.x86_64                 5.0.0-13.el6                base
bacula-storage-mysql.x86_64                  5.0.0-13.el6                base
dovecot-mysql.x86_64                         1:2.0.9-22.el6              base
freeradius-mysql.x86_64                      2.2.6-7.el6_9               updates
libdbi-dbd-mysql.x86_64                      0.8.3-5.1.el6               base
mod_auth_mysql.x86_64                        1:3.0.0-11.el6_0.1          base
mod_auth_mysql-debuginfo.x86_64              1:3.0.0-11.el6_0.1          debug
mysql.x86_64                                 5.1.73-8.el6_8              base
mysql-bench.x86_64                           5.1.73-8.el6_8              base
mysql-connector-java.noarch                  1:5.1.17-6.el6              base
mysql-connector-odbc.x86_64                  5.1.5r1144-7.el6            base
mysql-debuginfo.x86_64                       5.1.73-8.el6_8              debug
mysql-devel.i686                             5.1.73-8.el6_8              base
mysql-devel.x86_64                           5.1.73-8.el6_8              base
mysql-embedded.i686                          5.1.73-8.el6_8              base
mysql-embedded.x86_64                        5.1.73-8.el6_8              base
mysql-embedded-devel.i686                    5.1.73-8.el6_8              base
mysql-embedded-devel.x86_64                  5.1.73-8.el6_8              base
mysql-libs.i686                              5.1.73-8.el6_8              base
mysql-server.x86_64                          5.1.73-8.el6_8              base
mysql-test.x86_64                            5.1.73-8.el6_8              base
mysql55-mysql-debuginfo.x86_64               5.5.41-2.el6.centos.alt     debug
pcp-pmda-mysql.x86_64                        3.10.9-9.el6                base
qt-mysql.i686                                1:4.6.2-28.el6_5            base
qt-mysql.x86_64                              1:4.6.2-28.el6_5            base
rsyslog-mysql.x86_64                         5.8.10-10.el6_6             base
rsyslog7-mysql.x86_64                        7.4.10-7.el6                base
使用yum命令进行mysqld(mysql-server)安装

 yum install mysql-server
安装成功后,可通过如下命令查看安装的mysqld版本信息

[root@localhost ~]# rpm -qi mysql-server
Name        : mysql-server                 Relocations: (not relocatable)
Version     : 5.1.73                            Vendor: CentOS
Release     : 8.el6_8                       Build Date: Thu 26 Jan 2017 02:25:43 PM PST
Install Date: Tue 16 Jan 2018 12:15:32 AM PST      Build Host: c1bm.rdu2.centos.org
Group       : Applications/Databases        Source RPM: mysql-5.1.73-8.el6_8.src.rpm
Size        : 25884131                         License: GPLv2 with exceptions
Signature   : RSA/SHA1, Thu 26 Jan 2017 02:35:28 PM PST, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://www.mysql.com
Summary     : The MySQL server and related files
Description :
MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
client/server implementation consisting of a server daemon (mysqld)
and many different client programs and libraries. This package contains
the MySQL server and some accompanying files and directories.

二、启动mysql-server服务

使用root权限,执行:

/etc/init.d/mysqld start
或者:

service mysqld start
开启mysql-server

三、mysql登陆使用

开启mysql-server后,在普通账号下,登陆mysql成功:

[dup@localhost ~]$ mysql  
Welcome to the MySQL monitor.  Commands end with ; or \g.  
Your MySQL connection id is 3  
Server version: 5.1.73 Source distribution  
  
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.  
  
Oracle is a registered trademark of Oracle Corporation and/or its  
affiliates. Other names may be trademarks of their respective  
owners.  
  
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  
mysql> 
不过在root账户下,登陆mysql会有如下提示错误:

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


然后通过如下命令登陆:

[root@localhost ~]# mysql -u root -p

Enter password: 

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) denied for user 'root'@'localhost' (using password: NO)


应该是安装后没有设置root密码,需要设置root密码

[root@localhost ~]#mysqladmin -u root -p password 123456     ###设置root密码为123456

Enter password: 

mysqladmin: connect to server at 'localhost' failed

error: 'Access denied for user 'root'@'localhost' (using password: YES)'


但是依然有这个错误,网上查了下,使用如下方法解决了此问题:

[root@localhost ~]# /etc/init.d/mysqld stop

[root@localhost ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

[root@localhost ~]# mysql -u root mysql

mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';

mysql> FLUSH PRIVILEGES;

mysql> quit

[root@localhost ~]# /etc/init.d/mysqld restart

[root@localhost ~]# mysql -u root -p

Enter password: <输入新设的密码newpassword> 

mysql> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值