在OS X上设置MySQL root用户密码

我刚刚在Mac OS X上安装了MySQL。下一步是设置root用户密码,因此我下一步是这样做:


启动终端应用程序以访问Unix命令行。

在Unix提示符下,我执行了以下命令:


$ cd /usr/local/mysql/bin

$ ./mysqladmin -u root password 'password'

但是,当我执行命令时


$ ./mysql -u root,这就是答案:


Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 224

Server version: 5.5.13 MySQL Community Server (GPL)


Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql>

我可以mysql不用任何密码进入命令行!


为什么是这样?


拉风的咖菲猫
浏览 404回答 3
3回答

拉丁的传说

FLUSH PRIVILEGES登录到MySQL终端时,请尝试使用该命令。如果这不起作用,请在MySQL终端中尝试以下命令集$ mysql -u rootmysql> USE mysql;mysql> UPDATE user SET password=PASSWORD("NEWPASSWORD") WHERE User='root';mysql> FLUSH PRIVILEGES;mysql> quit使用您想要的任何密码更改出NEWPASSWORD。应该全部设置好!更新:从MySQL 5.7开始,该password字段已重命名authentication_string。更改密码时,请使用以下查询来更改密码。所有其他命令保持不变:mysql> UPDATE user SET authentication_string=PASSWORD("NEWPASSWORD") WHERE User='root';更新:在8.0.15(可能已经在该版本之前)上,PASSWORD()函数不起作用,如以下注释中所述。您必须使用:UPDATE mysql.user SET authentication_string='password' WHERE User='root';

largeQ

安装MySQL后,您需要建立“ root”密码。如果您没有建立root密码,那么,就没有root密码,并且您不需要密码即可登录。因此,话虽如此,您需要建立一个root密码。使用终端输入以下内容:安装:设置root用户密码:/usr/local/mysql/bin/mysqladmin -u root password NEW_PASSWORD_HERE如果您输入有误,或者需要更改root密码,请使用以下命令:更改root密码:cd /usr/local/mysql/bin/./mysql -u root -p> Enter password: [type old password invisibly]use mysql;update user set password=PASSWORD("NEW_PASSWORD_HERE") where User='root';flush privileges;quit
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MySQL