我的问题可能是重复的,因为我搜索了一堆东西,但是对于MySQL来说还是很新的,对Ubuntu来说也不太老,我正在研究raspberry,并尝试安装MySQL服务器来扩展映像。
使用以下方法安装MySQL服务器:
sudo apt install mariadb-server
默认情况下,安装MySQL时没有设置任何密码,这意味着您可以在不进行任何身份验证的情况下访问MySQL服务器。
在将MySQL服务器软件安装到Raspberry之后,我们现在需要通过为“root”用户设置密码来保护它。
运行以下命令开始MySQL安全过程
sudo mysql_secure_installation
在此之后,接下来的事情发生了,我更改了密码和其余的问题,我说了y
,然后继续前进。
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
现在,当我使用以下命令访问MySQL服务器时
sudo mysql -u root -p
它要求输入密码,所以我输入密码,我输入了上面设置的密码,它可以工作。
但奇怪的是,即使我只是按回车后,放置sudo mysql -u root -p
,它的工作。
当我输入mysql -u root -p
时,它会询问我输入的密码,而我输入的密码与上面的设置相同,这一次它不起作用,并给出了错误。
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
有人能帮我解释一下为什么会发生这样的事情吗?
发布于 2020-01-31 08:18:00
根用户需要'sudo‘。使用以下命令创建新用户:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database_name.* TO 'newuser'@'localhost';
现在,新用户无需sudo要求就可以登录:
mysql -u newuser -p
https://askubuntu.com/questions/1206892
复制相似问题