MySQL 如何通过终端在ubuntu中运行mysql

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11188351/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:56:59  来源:igfitidea点击:

how to run mysql in ubuntu through terminal

mysqlubuntu

提问by Raj Singhania

trying to run mysql in ubuntu typing mysqlin terminal and getting error

尝试在 ubuntu 中运行 mysqlmysql在终端中输入并出现错误

ERROR 1045(28000): Access denied for user 'root'@'localhost' (using password: NO)

Can anybody please sort out this problem...

有大佬能解决一下这个问题吗...

回答by lorenzo-s

You have to give a valid username. For example, to run query with user rootyou have to type the following command and then enter password when prompted:

您必须提供有效的用户名。例如,要使用用户运行查询,root您必须键入以下命令,然后在出现提示时输入密码:

mysql -u root -p

Once you are connected, prompt will be something like:

连接后,提示将类似于:

mysql>

Here you can write your query, after database selection, for example:

在选择数据库后,您可以在此处编写查询,例如:

mysql> USE your_database;
mysql> SELECT * FROM your_table;

回答by matcheek

If you want to run your scripts, then

如果你想运行你的脚本,那么

mysql -u root -p < yourscript.sql

回答by John Kane

You need to log in with the correct username and password. Does the user root have permission to access the database? or did you create a specific user to do this?

您需要使用正确的用户名和密码登录。用户root是否有访问数据库的权限?或者您是否创建了特定用户来执行此操作?

The other issue might be that you are not using a password when trying to log in.

另一个问题可能是您在尝试登录时没有使用密码。

回答by Prakhar Agrawal

You seem to just have begun using mysql.

你好像刚开始用mysql。

Simple answer: for now use

简单的答案:现在使用

mysql -u root -p password

mysql -u root -p 密码

Password is usually root by default. You may use other usernames if you have created other user using create user in mysql. For details use "help, help manage accounts, help create users" etc. If you dont want your password to be shown in open just press return key after "-p" and you will be prompted for password next. Hope this resolves the issue.

默认情况下,密码通常是 root。如果您在 mysql 中使用 create user 创建了其他用户,则可以使用其他用户名。有关详细信息,请使用“帮助,帮助管理帐户,帮助创建用户”等。如果您不想在打开时显示您的密码,只需在“-p”后按回车键,接下来将提示您输入密码。希望这能解决问题。