简体   繁体   English

MySQL CentOS:用户''@'localhost'对数据库的访问被拒绝

[英]MySQL CentOS : Access denied for user ''@'localhost' to database

I installed MySQL in CentOS using sudo yum install mysql-server and logged into MySQL using mysql -u root -p and gave blank password.我使用sudo yum install mysql-server在 CentOS 中安装了 MySQL,并使用mysql -u root -p登录到 MySQL 并给出了空白密码。 It's not allowing me to use MySQL database or select users/update password/create database.它不允许我使用 MySQL 数据库或选择用户/更新密码/创建数据库。

mysql> select user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

mysql> use mysql;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

mysql> UPDATE user SET Password=PASSWORD('*****') WHERE user='root';
ERROR 1046 (3D000): No database selected

mysql> show grants;
+--------------------------------------+
| Grants for @localhost                |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+
1 row in set (0.00 sec)


[centos@****~]$ sudo /sbin/service mysqld stop
Redirecting to /bin/systemctl stop  mysqld.service
[centos@****~]$ sudo mysqld_safe
151026 14:40:32 mysqld_safe Logging to '/var/log/mysqld.log'.
151026 14:40:32 mysqld_safe A mysqld process already exists
[centos@*****~]$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 152
Server version: 5.6.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> use mysql;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
mysql>

Error Again:再次出错:

[centos@~]$ sudo /sbin/service mysqld stop
Redirecting to /bin/systemctl stop  mysqld.service
[centos~]$ sudo mysqld_safe --skip-grant-tables &
[1] 25678
[centos~]$ 151026 14:53:07 mysqld_safe Logging to '/var/log/mysqld.log'.
151026 14:53:07 mysqld_safe A mysqld process already exists

[1]+  Exit 1                  sudo mysqld_safe --skip-grant-tables
[centos@~]$ sudo mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 160
Server version: 5.6.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> use mysql;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

Please let me know how to resolve this.请让我知道如何解决这个问题。

  1. sudo /etc/init.d/mysql stop
  2. sudo mysqld_safe --skip-grant-tables &
  3. sudo mysql -u root
  4. Setup new MySQL root user password设置新的 MySQL 根用户密码

    use mysql; update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root'; flush privileges; quit
  5. Stop MySQL Server: sudo /etc/init.d/mysql stop (if any error use sudo )停止 MySQL 服务器: sudo /etc/init.d/mysql stop (如果有任何错误使用sudo

  6. Start MySQL server and test it: sudo mysql -u root -p启动 MySQL 服务器并测试: sudo mysql -u root -p

If you have no Password set, you can't give the -p Parameter with the mysql command.如果您没有设置密码,则不能在 mysql 命令中提供 -p 参数。 Start it only with mysql -u root仅使用mysql -u root启动它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM