如何在 OS X 上以 root 身份登录 MySQL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11403980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I login as root on MySQL on OS X?
提问by andrewb
I've just set up MySQL on my computer (OS X 10.7), and it seems to be working, judging by the "mysqld" in the activity monitor and the new icon in my System Preferences.
我刚刚在我的计算机(OS X 10.7)上设置了 MySQL,从活动监视器中的“mysqld”和我的系统偏好设置中的新图标来看,它似乎正在运行。
However I'm having trouble doing anything with MySQL, as I need to login at least as the root user, but it doesn't let me. So let's run through what I've been doing and what error messages I'm getting:
但是,我在使用 MySQL 时遇到问题,因为我至少需要以 root 用户身份登录,但它不允许我这样做。那么让我们来看看我一直在做什么以及我收到了什么错误消息:
Firstly, I start up MySQL via the "mysql" unix executable file. This seems to work, as my entries are now preceded with
首先,我通过“mysql”unix 可执行文件启动 MySQL。这似乎有效,因为我的条目现在以
mysql>
Also, I can type
另外,我可以输入
help;
and I get MySQL's help list. So then I go to do something, like create a database:
我得到了 MySQL 的帮助列表。然后我去做一些事情,比如创建一个数据库:
CREATE DATABASE books;
but I get the following error:
但我收到以下错误:
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'books'
So then I figure I need to login, and that logging in as the root user should be enough. I enter the following:
然后我想我需要登录,并且以 root 用户身份登录应该就足够了。我输入以下内容:
mysql -u root -p;
But I get the 1064 error saying my syntax is wrong. I've had a look around through a number of websites, and this never seems to be a problematic step. Any clues on what's going wrong for me?
但是我收到 1064 错误,说我的语法错误。我浏览了许多网站,这似乎从来都不是一个有问题的步骤。关于我出了什么问题的任何线索?
回答by
At the OSX Terminal promptyou enter mysql -u root
to actually start the command line client that connects to the server.
在OSX 终端提示符下,您输入mysql -u root
以实际启动连接到服务器的命令行客户端。
shell>
represents whatever your shell prompt actually looks like.
shell>
代表您的 shell 提示实际上是什么样的。
You do notenter this in afteryou have already typed mysql
at the command line prompt.
你不能在进入这个之后,你已经输入mysql
的命令行提示符。
Here is an example session:
这是一个示例会话:
shell> mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'::1' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'host_name' = PASSWORD('newpwd');
NOTE:you might need to preface the
shell> mysql -u root
withshell> sudo mysql -u root
注意:您可能需要在前面
shell> mysql -u root
加上shell> sudo mysql -u root
My shell prompt is customized to be[jhr@Blackintosh] [/usr/local/mysql-5.5.25a-osx10.6-x86_64/bin]
with a \n
on the end so ./mysql -u root
it typed at the on the next line down. The rest is what the output of that command should be. The shell prompt is replaced by the prompt of the mysql
program prompt.
我的 shell 提示被自定义为在末尾[jhr@Blackintosh] [/usr/local/mysql-5.5.25a-osx10.6-x86_64/bin]
带有 a \n
,因此./mysql -u root
它在下一行键入。其余的是该命令的输出应该是什么。shell 提示被mysql
程序提示的提示替换。
Here is what my shell output looks like
这是我的 shell 输出的样子
[jhr@Blackintosh] [/usr/local/mysql-5.5.25a-osx10.6-x86_64/bin]
./mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.25a MySQL Community Server (GPL)
Copyright (c) 2000, 2011, 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>
回答by d1jhoni1b
Executing this command:
执行这个命令:
mysql -u root -p
Will prompt on your console:
将在您的控制台上提示:
#:=> Enter password: [enter your pass]
That way you can login mysql dbms
这样你就可以登录mysql dbms
回答by Storm_troopa
i was having this problem recently and realized my login path was bin/bash so incase anyone else has this problem heres how i fixed it. if you have XAMPP installed go to your applications folder then go to the XAMPP folder. then go to the bin folder. if you are in the bin folder, this will be your path to use the following command
我最近遇到了这个问题,并意识到我的登录路径是 bin/bash,所以如果其他人有这个问题,我是如何修复它的。如果您安装了 XAMPP,请转到您的应用程序文件夹,然后转到 XAMPP 文件夹。然后转到bin文件夹。如果您在 bin 文件夹中,这将是您使用以下命令的路径
mysql -uroot
now open your terminal application and on the top left click on terminal and then preferences. where it says "shell open with", select the default option then close your terminal window. now reopen it and your terminal should start like this
现在打开您的终端应用程序,然后在左上角单击终端,然后单击首选项。在它说“shell open with”的地方,选择默认选项,然后关闭你的终端窗口。现在重新打开它,你的终端应该像这样开始
Last login: Mon Dec 18 12:06:25 on ttys
[yourname]-air:~ [yourname]$
now type the path
现在输入路径
/Applications/XAMPP/bin/mysql -uroot
回答by cybertextron
mysql -u root
if you have a password setup, or mysql -u root -p root
if you don't.
mysql -u root
如果您设置了密码,或者mysql -u root -p root
没有。
This will prompt the root
password.
I always use the mac terminal anyways. When you install, just using mysql
you can log in, and you can setup the password for the root
.
I also advice you to read Creating a MySQL user
这将提示输入root
密码。反正我总是使用mac终端。安装时只需使用mysql
即可登录,设置密码即可root
。我还建议您阅读创建 MySQL 用户
回答by randoo
When you first start using mysql on mac none of the accounts have passwords, not even root. So you can login with root and no password and then you must set passwords as explained by Jarrod, or for more detail read: http://dev.mysql.com/doc/refman/5.0/en/default-privileges.html
当您第一次在 mac 上开始使用 mysql 时,没有一个帐户有密码,甚至 root 也没有。因此,您可以使用 root 登录而无需密码,然后您必须按照 Jarrod 的说明设置密码,或者有关更多详细信息,请阅读:http: //dev.mysql.com/doc/refman/5.0/en/default-privileges.html