我一直在按照手册在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)
我该如何修复它并继续?
虽然上面的答案(使用mysqladmin)在macOS v10.15 (Catalina)上有效,但在Ubuntu上无效。然后我尝试了许多其他的选项,包括MySQL的安全启动,但都不起作用。
下面是一个例子:
至少在这个版本中,我得到了5.7.28-0ubuntu0.18.04.4的答案缺少IDENTIFIED WITH mysql_native_password。5.7.28是当前LTS的默认设置,因此应该是大多数新系统的默认设置(直到Ubuntu 20.04 (Focal Fossa) LTS问世)。
我发现不能设置root密码MySQL服务器,现在应用
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_pass_here';
这是可行的。
在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
我使用的是mysql-5.7.12-osx10.11-x86_64。dmg在Mac OS X上。
安装过程会自动为root用户设置一个临时密码。你应该保存密码。密码不可恢复。
按照说明操作:
Go to cd /usr/local/mysql/bin/
Enter the temporary password (which would look something like, "tsO07JF1=>3")
You should get the mysql> prompt.
Run, SET PASSWORD FOR 'root'@'localhost' = PASSWORD('{YOUR_PASSWORD}'); If you wish to set your password: "root" then the command would be, SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');
Run ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
Run exit
Run ./mysql -u root -p
Type your password. In my case I would type, "root" (without quote)
That's all.
为了方便起见,您应该在PATH环境变量中添加“/usr/local/mysql/bin”。
现在你可以在任何地方输入。/mysql -u root -p,然后输入密码,你会得到mysql>提示。
在服务器初始启动时,假设服务器的数据目录为空,会发生以下情况:
完成服务器的初始化。
在data目录下生成SSL证书和密钥文件。
安装并启用validate_password插件。
创建超级用户帐户“root”@“localhost”。超级用户的密码被设置并存储在错误日志文件中。
要显示它,使用以下命令:
Shell > sudo grep '临时密码' /var/log/mysqld.log
请使用临时密码登录,并自定义超级用户密码,尽快修改root用户密码:
Shell > mysql的root -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass5!