ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
尝试了N种方法,最终用以下方法解决了:
复制代码
1、首先到安装目录下找到初始化的账号密码
root@NaiYou:~# cd /etc/mysql/
root@NaiYou:/etc/mysql# ls
conf.d debian.cnf debian-start my.cnf
2、查看账户密码
root@NaiYou:/etc/mysql# cat debian.cnf
# Auto某公司ally generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = XXXXXXXX
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = XXXXXXXX
socket = /var/run/mysqld/mysqld.sock
basedir = /usr
3、使用client的账户密码登陆mysql命令行
root@NaiYou:/etc/mysql# mysql -udebian-sys-maint -p
4、更新root用户的密码
mysql> use mysql;
mysql> UPDATE user SET Password=PASSWORD('123456') where USER='root';
mysql> quit
5、现在可以用Root用户登陆了root@NaiYou:/etc/mysql# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2247
Server version: 5.5.44-0ubuntu0.14.04.1 (Ubuntu)