使用 mysql 5.5.8 命令行设置密码的正确语法

发布于 2024-12-05 07:52:30 字数 722 浏览 1 评论 0原文

我刚刚下载并安装了 WAMPserver 2.1,我想为 MySQL 5.5.8 数据库设置密码。我正在 lynda.com 上做一个教程,导师 (Kevin Skoglund) 指示输入:

mysql> use mysql
Database changed

mysql> UPDATE user
    -> SET Password = PASSWORD('paSSword')
    -> WHERE user = 'root';

当我按 Enter 键时,我收到有关 WHERE 语句的错误:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual
  that corresponds to your MySQL server version for the right syntax to use
  near 'WHERE' user='root'; at line 2

有谁知道 WHERE 语句的正确语法吗?他的课程是在 2007 年完成的,所以我猜语法已经改变了,因为它在视频中对他有用。为他返回了这一行:

Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1  Warnings: 0
mysql>

谢谢

I've just downloaded and installed WAMPserver 2.1 and I want to set a password for the MySQL 5.5.8 database. I'm doing a tutorial at lynda.com and the tutor (Kevin Skoglund) instructions to type:

mysql> use mysql
Database changed

mysql> UPDATE user
    -> SET Password = PASSWORD('paSSword')
    -> WHERE user = 'root';

When I hit enter, I get this error about the WHERE statement:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual
  that corresponds to your MySQL server version for the right syntax to use
  near 'WHERE' user='root'; at line 2

Does anyone know the correct syntax for the WHERE statement? His lessons were done in 2007, so I guess the syntax has changed because it worked for him in the video. This line was returned for him:

Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1  Warnings: 0
mysql>

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

关于从前 2024-12-12 07:52:30

这适用于我的测试服务器:

mysql> UPDATE user SET password=PASSWORD('newpassword') WHERE user ='root';
mysql> Query OK

您正在尝试设置密码而不是密码(小写)

Shai。

This works on my test server:

mysql> UPDATE user SET password=PASSWORD('newpassword') WHERE user ='root';
mysql> Query OK

You are trying to set Password instead of password (lowercased)

Shai.

想念有你 2024-12-12 07:52:30

我在使用 lynda.com 教程时遇到了同样的问题。解决办法是:

UPDATE mysql.user SET Password=PASSWORD('cleartext password')
WHERE User='root';
FLUSH PRIVILEGES;

I was having the same problem with the same lynda.com tutorial. The solution is:

UPDATE mysql.user SET Password=PASSWORD('cleartext password')
WHERE User='root';
FLUSH PRIVILEGES;
时间你老了 2024-12-12 07:52:30

以 root 身份登录 mysql,然后

SET PASSWORD FOR 'user-name-here'@'hostname-name-here' = PASSWORD('new-password-here');

进行真实场景

SET PASSWORD FOR 'user_test'@'localhost' = PASSWORD('hello');

Login to mysql as root, then

SET PASSWORD FOR 'user-name-here'@'hostname-name-here' = PASSWORD('new-password-here');

For a real scenario

SET PASSWORD FOR 'user_test'@'localhost' = PASSWORD('hello');
昔日梦未散 2024-12-12 07:52:30

我遇到了完全相同的问题,问题解决如下:

更新 mysql.user SET 密码=PASSWORD('YourPassword') WHERE User='root';

注意:问题是我将 <>(尖括号)而不是 ()(圆括号)放入程序中,我知道这听起来很愚蠢,但这就是发生的事情。因为 () 和 <>看起来在命令行上看起来是一样的,我把它们搞乱了。

I was having exactly the same problem, the problem was solved as follows:

UPDATE mysql.user SET Password=PASSWORD('YourPassword') WHERE User='root';

NOTE: The problem was that I put <>(angle brackets) instead of () (round brackets) into the program, I know it sounds really dumb, but this is what happened. Because () and <> appear to look the same on command line, I messes them up.

机场等船 2024-12-12 07:52:30

这段代码:

UPDATE user SET password=PASSWORD('newpassword') WHERE user ='root';

将编译(因为需要一个更好的词),但它是非常不安全的代码:

MySQL 手册对此是这么说的:

注意
PASSWORD()函数供MySQL Server中的身份验证系统使用;您不应该不要在您自己的应用程序中使用它。为此,请考虑使用 MD5() 或 SHA1()。另请参阅 RFC 2195 第 2 部分(质询响应身份验证机制 (CRAM)),了解有关在应用程序中安全处理密码和身份验证的更多信息。

如果您坚持将密码存储在数据库中,则应始终对它们加盐并使用安全哈希。
MD5 和 SHA1 不再安全。 2005 年(!)该主题的领先专家 Bruce Scheier 表示:“我们所有人都应该放弃 SHA-1。”
我建议使用哈希长度为 512 位的 SHA2。

$user = mysql_real_escape_string($_POST['user']);
$password1 = mysql_real_escape_string($_POST['password1']);
$password2 = mysql_real_escape_string($_POST['password2']);
$oldpassword = mysql_real_escape_string($_POST['oldpassword']);

if not(empty($password1) and ($password1 == $password2) {
  $update = "UPDATE user 
  SET passhash = SHA2(CONCAT(id,'$password1'),512) 
  WHERE user = '$user' AND passhash = SHA2(CONCAT(id,'$oldpassword'),512)";

这确保用户只有在知道旧密码的情况下才能更改密码。

盐需要与密码存储在同一行,但不需要保密。
只需确保将其作为密码前缀即可。

测试密码的工作原理如下:

SELECT * FROM user 
WHERE username = 'root' 
  AND passhash = SHA2(CONCAT(id,'passwordexample'),512)

This code:

UPDATE user SET password=PASSWORD('newpassword') WHERE user ='root';

Will compile (for want of a better word), but is very insecure code:

Here's what the MySQL manual says about it:

Note
The PASSWORD() function is used by the authentication system in MySQL Server; you should not use it in your own applications. For that purpose, consider MD5() or SHA1() instead. Also see RFC 2195, section 2 (Challenge-Response Authentication Mechanism (CRAM)), for more information about handling passwords and authentication securely in your applications.

If you insist on storing passwords in your database, you should always salt them and use a secure hash.
MD5 and SHA1 are no longer secure. In 2005 (!) Bruce Scheier, a leading expert on this topic said: "It's time for us all to migrate away from SHA-1."
I suggest using SHA2 with a 512 bits hash length.

$user = mysql_real_escape_string($_POST['user']);
$password1 = mysql_real_escape_string($_POST['password1']);
$password2 = mysql_real_escape_string($_POST['password2']);
$oldpassword = mysql_real_escape_string($_POST['oldpassword']);

if not(empty($password1) and ($password1 == $password2) {
  $update = "UPDATE user 
  SET passhash = SHA2(CONCAT(id,'$password1'),512) 
  WHERE user = '$user' AND passhash = SHA2(CONCAT(id,'$oldpassword'),512)";

This ensures that the user can only change the password when he knows the old password.

The salt needs to be stored in the same row as the password, but does not need to be secret.
Just make sure you prefix it to the password.

Testing the password works like:

SELECT * FROM user 
WHERE username = 'root' 
  AND passhash = SHA2(CONCAT(id,'passwordexample'),512)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文