我一直在按照手册在Ubuntu上安装软件套件。我完全不了解MySQL。我已经在我的Ubuntu上完成了以下安装。

sudo apt-get update
sudo apt-get install mysql-server-5.5
sudo apt-get install mysql-client-5.5
sudo apt-get install mysql-common
sudo apt-get install glade
sudo apt-get install ntp

然后我做了

cd ~/Desktop/iPDC-v1.3.1/DBServer-1.1
mysql -uroot -proot <"Db.sql"

我最终得到以下错误消息。

错误1045(28000):拒绝访问用户'root'@'localhost'(使用密码:YES)

我该如何修复它并继续?


当前回答

在Ubuntu 16.04 (Xenial Xerus)和MySQL 5.7.13版本中,我能够通过以下步骤解决这个问题:

Follow the instructions from section B.5.3.2.2 Resetting the Root Password: Unix and Unix-Like Systems MySQL 5.7 reference manual When I tried #sudo mysqld_safe --init-file=/home/me/mysql-init & it failed. The error was in /var/log/mysql/error.log: 2016-08-10T11:41:20.421946Z 0 [Note] Execution of init_file '/home/me/mysql/mysql-init' started. 2016-08-10T11:41:20.422070Z 0 [ERROR] /usr/sbin/mysqld: File '/home/me/mysql/mysql-init' not found (Errcode: 13 - Permission denied) 2016-08-10T11:41:20.422096Z 0 [ERROR] Aborting

mysql-init的文件权限不是问题。我们需要编辑AppArmor权限。

Edit by sudo vi /etc/apparmor.d/usr.sbin.mysqld .... /var/log/mysql/ r, /var/log/mysql/** rw, # Allow user init file /home/pranab/mysql/* r, # Site-specific additions and overrides. See local/README for details. #include <local/usr.sbin.mysqld> } Do sudo /etc/init.d/apparmor reload Start mysqld_safe again. Try step 2 above. Check file /var/log/mysql/error.log. Make sure there is no error and the mysqld is successfully started. Run mysql -u root -p Enter password: Enter the password that you specified in mysql-init. You should be able to log in as root now. Shutdown mysqld_safe by sudo mysqladmin -u root -p shutdown Start mysqld the normal way by sudo systemctl start mysql

其他回答

在我的情况下,我试图传递一个shell命令到docker容器。在这种情况下,只有第一个词被解释。确保你没有在运行:

mysql

相对于:

mysql -uroot -ppassword schemaname

也许可以试着引用:

'mysql -uroot -ppassword schemaname'

我尝试了Lahiru的正确答案,但它不能与macOS v10.14 (Mojave)上的MySQL服务器版本8.0.16 (Community)一起工作。

我遵循Sameer Choudhary的指示,并进行了一些调整,我能够更改根密码,并从本地主机启用根访问。

所有这些都不是必需的。如果您正在使用Homebrew在Mac OS上安装:

brew install mysql

我也遇到过类似的问题:

错误1045(28000):用户“root”@“localhost”(正在使用)被拒绝访问 密码:没有)

但对我来说,这个原因真的很愚蠢。 我从Word文档复制了该命令,问题是连字符没有ASCII 0x2D代码,而是Unicode 0xE2 0x80 0x93 UTF-8序列(代码点U+2013 EN DASH)。

错误的方式:

mysql -u root –pxxxx

正确的方式:

mysql -u root -pxxxx

两者看起来一样,但并不相同(尝试一下,复制和粘贴替换密码)。

面对这种类型的错误,建议尝试输入命令,而不是复制和粘贴。

我使用Ubuntu 16.04 (Xenial Xerus)和安装MySQL 5.7。

我也有同样的问题

禁止root用户登录。

我尝试了以下步骤:

get-select | grep mysql(获取mysql版本)。 dpkg-reconfigure mysql -服务器- 5.7 Mysql -u root -p

如果没有-p,则不会提示您询问密码。进入后,您可以按照以下步骤创建一个带有密码的用户:

CREATE USER 'your_new_username'@'your-hostname' IDENTIFIED BY 'your-password';

GRANT ALL PRIVILEGES ON *.* to 'your_new_username'@'your-hostname' WITH GRANT OPTION;

从根目录退出,从上面给出的<name>登录。

mysql -u <your_new_username> -p

由于某种原因,仍然不能输入MySQL。在所有。我建议养成使用mysql -u <name> -p的习惯。

2021年。

回答Ubuntu 20.04 (Focal Fossa)(也可能是其他发行版)。

在四处游荡了几天之后…这些答案对我都没用,我就这么做了,而且成功了!

始终在Bash shell中:

sudo systemctl disable mysql

为了阻止守护进程在启动时启动。

sudo apt purge mysql-server

and

sudo apt purge mysql-community-server*

在那里,它警告你,你将删除配置文件…所以它起作用了!因为他们就是捣乱的人!

sudo autoremove

删除所有遗留的包。

然后重启(也许这是可选的,但我做到了)。 另外,我从MySQL官方网页下载了MySQL -server-8.0:

sudo apt install mysql-server

它正在工作的信号是,当您输入上面的命令时,系统要求您输入根密码。

最后:

mysql -u root -p

还有你之前输入的密码。