我需要替换远程 ubuntu 20 服务器上的 mysql 凭据,但无法使用命令进入 mysql 控制台
root@remote-server:/var/www/html/project# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
root@remote-server:/var/www/html/project# dpkg -s mysql
dpkg-query: package 'mysql' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files.
root@remote-server:/var/www/html/project# dpkg -s mysql-server
Package: mysql-server
Status: install ok installed
Priority: optional
Section: database
Installed-Size: 35
Maintainer: Ubuntu Developers <[email protected]>
Architecture: all
Source: mysql-8.0
Version: 8.0.34-0ubuntu0.20.04.1
Depends: mysql-server-8.0
Description: MySQL database server (metapackage depending on the latest version)
This is an empty package that depends on the current "best" version of
mysql-server (currently mysql-server-8.0), as determined by the MySQL
maintainers. Install this package if in doubt about which MySQL
version you need. That will install the version recommended by the
package maintainers.
.
MySQL is a fast, stable and true multi-user, multi-threaded SQL database
server. SQL (Structured Query Language) is the most popular database query
language in the world. The main goals of MySQL are speed, robustness and
ease of use.
Homepage: http://dev.mysql.com/
Original-Maintainer: Debian MySQL Maintainers <[email protected]>
root@remote-server:/var/www/html/project# uname -a
Linux remote-server 5.4.0-155-generic #172-Ubuntu SMP Fri Jul 7 16:10:02 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
root@remote-server:/var/www/html/project# who -H
NAME LINE TIME COMMENT
root pts/0 2023-10-30 09:13 (213.109.234.130)
当我使用 ssh 打开远程服务器时,我看到自己处于 root 权限下?为什么会出现此错误?我该如何修复?
答案1
这个错误很容易解释:用户root
没有被授予访问 mySQL 数据库的权限。或者,至少,用户需要您提供的密码。这很好!您肯定不想让 root 用户在 DB 中乱搞!请记住,DB 用户和系统用户是不同的。
您需要查看数据库设置,创建用户并授予该用户访问权限。如果您不知道如何操作,请咨询负责维护数据库的人员。
如果您要维护此内容,那么我建议您阅读更多有关数据库设置的信息。如果您仍然需要帮助,那么您可以发布一个新问题,解释您的设置以及您仍然需要哪些帮助。