解决mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
一,基本环境操作系统:Red Hat Enterprise Linux Server release 6.8mysql版本:mysql-community-server-5.7.21二,流程2.1,安装mysql完成后,启动mysql报错[root@postgredb mysql]# mysql -u root -pEnter password:ERROR 1045 (28000): Acc...
·
一,基本环境
操作系统:Red Hat Enterprise Linux Server release 6.8
mysql版本:mysql-community-server-5.7.21
二,流程
2.1,安装mysql完成后,启动mysql报错
[root@postgredb mysql]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
2.2,编辑配置文件
加入参数skip-grant-tables
[root@postgredb etc]# vi my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
2.3,重启服务
[root@postgredb etc]# service mysqld stop
停止 mysqld: [确定]
[root@postgredb etc]# service mysqld start
正在启动 mysqld: [确定]
2.4,登陆mysql
在输入密码阶段,直接回车登陆
[root@postgredb etc]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.21 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
2.5,修改密码
mysql> update mysql.user set authentication_string=password('tpc1989') where user='root' and host='localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> quit;
Bye
[root@postgredb etc]#
2.6,去掉参数,重启mysql
至此,问题等到解决。
更多推荐
已为社区贡献1条内容
所有评论(0)