您的位置:首页 > 数据库 > MySQL

mac下MySQL修改root初始密码

2016-03-08 22:56 651 查看
       
新装的mysql在登录时需要注意:

For example, if you run the server using the mysql login account, you should log in as mysql before using the instructions. Alternatively, you can log in as root, but in this case you must start mysqld with the --user=mysql option. If you start the server as root without using --user=mysql, the server may create root-owned files in the data directory, such as log files, and these may cause permission-related problems for future server startups.

(以上内容来自官方文档)

在使用root用户登录时,需要加上--user=mysql,否则服务器将会在数据目录下洗创建一个root-owned文件,这样在服务器启动的时候会引起权限问题。(未尝试--user=mysql,新装完mysql的同学可以尝试下)

        现在到这里,已经登录不了mysql了,要么是ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:
NO),

要么是ERROR 1045 (28000): Access
denied for user 'root'@'localhost' (using password:  YES),现在如何做?

        在终端下输入:cd
/usr/local/mysql/bin/

 
      使用管理员权限:sudo su

 
      回车后输入以下命令来禁止mysql验证功能

        ./mysqld_safe --skip-grant-tables &
        之后mysql会自动重启,完成之后打开mysql workbench,在Query窗口执行flush privileges,再执行set
password for root='<your password>',执行完之后,就可以使用新的root密码来登录mysql了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql server 密码 mac