php 如何在 mysql 上找到我的本地主机和用户名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2335472/
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 find my local host and username on mysql?
提问by Audel
I need to open my database through PHP but I need to know my username and the name of my localhost, and i don't know them.
我需要通过 PHP 打开我的数据库,但我需要知道我的用户名和我的本地主机的名称,而我不知道它们。
When i used mysql and did my database it just asked me directly for a password.
当我使用 mysql 并创建我的数据库时,它只是直接要求我输入密码。
回答by adharris
The default username is root. You can reset the root password if you do not know it: http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html. You should not, however, use the root account from PHP, set up a limited permission user to do that: http://dev.mysql.com/doc/refman/5.1/en/adding-users.html
默认用户名是 root。如果您不知道,您可以重置 root 密码:http: //dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html。但是,您不应该使用 PHP 的 root 帐户,设置一个有限权限的用户来执行此操作:http: //dev.mysql.com/doc/refman/5.1/en/adding-users.html
If MySql is running on the same computer as your webserver, you can just use "localhost" as the host
如果 MySql 与您的网络服务器在同一台计算机上运行,您可以使用“localhost”作为主机
回答by d-coder
type this command
输入这个命令
select CURRENT_USER();
You will get the username and server
您将获得用户名和服务器
回答by antyrat
Default user for MySQL is "root", and server "localhost".
MySQL 的默认用户是“root”,服务器是“localhost”。
回答by JSB????
You should be able to access the local database by using the name localhost. There is also a way to determine the hostname of the computer you're running on, but it doesn't sound like you need that. As for the username, you can either (1) give permissions to the account that PHP runs under to access the database without a password, or (2) store the username and password that you need to connect with (hard-coded or stored in a config file), and pass those as arguments to mysql_connect. See http://php.net/manual/en/function.mysql-connect.php.
您应该能够使用 name 访问本地数据库localhost。还有一种方法可以确定您正在运行的计算机的主机名,但听起来您并不需要那样做。至于用户名,您可以(1)授予运行 PHP 的帐户的权限,无需密码即可访问数据库,或(2)存储您需要连接的用户名和密码(硬编码或存储在一个配置文件),并将它们作为参数传递给mysql_connect. 请参阅http://php.net/manual/en/function.mysql-connect.php。
回答by shubhy
if you are using mysql for the first time you can try using password as 123 or abc
如果您是第一次使用 mysql,您可以尝试使用密码为 123 或 abc
回答by Ibrahim Ansari
$servername = "localhost";
$username = "root";
$password = "";
This would most probably work for new users and don't forget to create the database before connecting to it.
这很可能适用于新用户,并且在连接之前不要忘记创建数据库。

