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

时间:2022-05-28 03:06:37

I installed MySQL in CentOS using sudo yum install mysql-server and logged into MySQL using mysql -u root -p and gave blank password. It's not allowing me to use MySQL database or select users/update password/create database.

我在CentOS中安装了MySQL,使用sudo yum安装MySQL -server,使用MySQL -u root -p登录到MySQL,并给出了空白密码。它不允许我使用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.

请告诉我如何解决这个问题。

2 个解决方案

#1


0  

  1. sudo /etc/init.d/mysql stop
  2. sudo /etc/init.d / mysql停止
  3. sudo mysqld_safe --skip-grant-tables &
  4. sudo mysqld_safe——skip-grant-tables &
  5. sudo mysql -u root
  6. sudo mysql - u根
  7. Setup new MySQL root user password

    设置新的MySQL根用户密码。

    use mysql;
    update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
    flush privileges;
    quit
    
  8. Stop MySQL Server: sudo /etc/init.d/mysql stop (if any error use sudo)

    停止MySQL服务器:sudo /etc/ init。d/mysql停止(如有错误请使用sudo)

  9. Start MySQL server and test it: sudo mysql -u root -p

    启动MySQL服务器并测试它:sudo MySQL -u root -p

#2


0  

If you have no Password set, you can't give the -p Parameter with the mysql command. Start it only with mysql -u root

如果没有设置密码,就不能使用mysql命令提供-p参数。从mysql -u根开始

#1


0  

  1. sudo /etc/init.d/mysql stop
  2. sudo /etc/init.d / mysql停止
  3. sudo mysqld_safe --skip-grant-tables &
  4. sudo mysqld_safe——skip-grant-tables &
  5. sudo mysql -u root
  6. sudo mysql - u根
  7. Setup new MySQL root user password

    设置新的MySQL根用户密码。

    use mysql;
    update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
    flush privileges;
    quit
    
  8. Stop MySQL Server: sudo /etc/init.d/mysql stop (if any error use sudo)

    停止MySQL服务器:sudo /etc/ init。d/mysql停止(如有错误请使用sudo)

  9. Start MySQL server and test it: sudo mysql -u root -p

    启动MySQL服务器并测试它:sudo MySQL -u root -p

#2


0  

If you have no Password set, you can't give the -p Parameter with the mysql command. Start it only with mysql -u root

如果没有设置密码,就不能使用mysql命令提供-p参数。从mysql -u根开始