【发布时间】:2015-01-24 00:16:34
【问题描述】:
我在 CentOS linux 上安装了 MySQL,并试图设置 root 密码。为此,我采取了以下步骤:
1.) I opened the terminal and typed in `su - ` to run as root.
2.) I then ran `mysql - u root`, which resulted in a lot of output and another prompt.
3.) I then typed in `UPDATE mysql.user SET Password=PASSWORD('NewPassHere')
WHERE User='root';`
但是第3步产生了以下错误:
-bash: syntax error near unexpected token `('
当我将步骤 3 更改为 UPDATE mysql.user SET Password='NewPassHere' WHERE User='root'; 时,我收到以下错误:
bash: UPDATE: command not found...
如何解决此错误,以便在 MySQL 中成功设置 root 密码?
根据 Chuck 的建议,我尝试了以下方法,但得到了以下结果:
[root@localhost ~]# /usr/bin/mysqladmin -u root password 'newpwd'
/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
下面两个命令也有下面两个结果:
[root@localhost ~]# sudo service mysqld status
Redirecting to /bin/systemctl status mysqld.service
mysqld.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
[root@localhost ~]# sudo service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Failed to issue method call: Unit mysqld.service failed to load: No such file or directory.
回答:
解决这个问题的方法是使用 yum remove 删除 mysql,然后明确地关注 the steps in this tutorial。但是,我在下面将 Chuck 的回答标记为已接受,因为他花了很多时间研究这个问题。
【问题讨论】: