我使用带有 mariadb 数据库的 Ubuntu。
我想对我的 sql 数据库进行 mysqldump,但总是出现以下错误:
mysqldump: Got error: 1045; "Access denied for user 'db_user-backups'@'localhosts' (using password: YES)" when trying to connect
引发此错误的命令如下:
sudo mysqldump --defaults-file=/etc/mysql/my.cnf lom
我已经将用户名和密码添加到 /etc/mysql/my.cnf,并确保 cnf 文件具有正确的权限:
[mysqldump]
user=db_user_backups
password=MyS3cretP4ssw0rD!
用户名和密码正确,我可以使用我的 SQL 客户端登录。
有人知道我做错了什么吗?
(顺便说一句:请原谅我是一名 Linux 初学者 ^^')
答案1
出现错误“拒绝用户‘db_user-backups’@‘localhosts’访问。您可以连接到数据库并使用以下命令示例为用户‘db_user-backups’授予权限:
连接到 Mysql:mysql -u root -p:
GRANT ALL PRIVILEGES ON *.* TO db_user-backups@'localhosts' IDENTIFIED BY 'password' with grant option;
flush privileges;
之后您可以重新连接 mysqldump。
答案2
尝试指定端口。我在 Windows 上使用 MySQL 8.0,但 Ubuntu 上也存在类似的问题。如果没有端口参数,我得到了同样的错误:
C:\Users\user>mysqldump -u root -p airlines_test > C:\...\test\airlines_test_dump.sql
Enter password: ******************
mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect
我通过指定要使用的端口解决了这个问题:-P 3306
:
C:\Users\user>mysqldump -u root -p -P 3306 airlines_test > C:\...\test\airlines_test_dump.sql
Enter password: ******************