简体   繁体   English

我使用哪个用户名/密码连接到mySQL

[英]Which username/password do I use to connect to mySQL

So, I'm SUPER new to mySQL. 因此,我是MySQL的超级新手。 Having issues connecting to my database with PHP. 使用PHP连接到我的数据库时遇到问题。 Hoping someone can point me in the right direction. 希望有人可以指出正确的方向。

I can login to our Cpanel using my username/password. 我可以使用我的用户名/密码登录到我们的Cpanel。 Using the web gui I was able to create a database. 使用Web gui,我能够创建数据库。

Now when I try to connect to the database (or even just the server for that matter) using PHP I get an error: 现在,当我尝试使用PHP连接到数据库(或什至只是服务器)时,出现一个错误:

Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'username'@'servername' (using password: YES) in /home/ropepart/public_html/techportal/sandbox/mysqltest.php on line 8 Connection failed: Access denied for user 'username'@'servername' (using password: YES) 警告:mysqli :: __ construct():(HY000 / 1045):在第8行的/home/ropepart/public_html/techportal/sandbox/mysqltest.php中,用户'username'@'servername'的访问被拒绝(使用密码:是)连接失败:用户'username'@'servername'的访问被拒绝(使用密码:是)

To me, it seems like this is a username/password error. 对我来说,这似乎是用户名/密码错误。 But I an using the same username/password that I use to login to the web gui. 但是我使用与登录Web GUI相同的用户名/密码。 Why can I successfully login there, but can't login with PHP? 为什么我可以在那里成功登录,但不能使用PHP登录?

Here's my code (taken pretty much directly from W3Schools): 这是我的代码(几乎直接来自W3Schools):

<?php
$servername = "servername";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
?>

(Hopefully it's obvious that I've changed my servername/username/password for the purposes of this post) (希望本文已更改了服务器名/用户名/密码,这很明显)

Check the details correctly, By deafult 正确检查详细信息,默认
host = localhost 主机=本地主机
username = root 用户名=根
password = (No password leave it as empty) 密码=(没有密码,请保留为空)
database = (your database) 数据库=(您的数据库)

<?php 

$connection = new mysqli('host','username','password','your_database');

if($connection->connect_error || $connection->error){

echo "error";

}else{

echo "done";

}

?>

you should add database name. 您应该添加数据库名称。

 <?php
 $servername = "localhost";
 $username = "root";
 $password = "";
 $dbname = "demo"

 // Create connection
 $conn = new mysqli($servername, $username, $password,$dbname);

 // Check connection
  if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
  } 
  echo "Connected successfully";
  ?>

//if you are using xampp you shoul locate this file you get information from this passwords.txt //如果您使用的是xampp,则应找到该文件,并从passwords.txt中获取信息

MySQL database username/password is not necessarily same as cPanel username & password. MySQL数据库的用户名/密码不一定与cPanel用户名和密码相同。

Here is what you should do: 这是您应该做的:

  1. Login to your cPanel 登录到您的cPanel
  2. From dashboard click "MySQL® Databases" 在仪表板上单击“MySQL®数据库”
  3. Add a new user from there ( https://prnt.sc/kpiby9 ). 从那里添加一个新用户( https://prnt.sc/kpiby9 )。 Just fill username and password (note down the password). 只需填写用户名和密码(记下密码)。
  4. Add that user with your database by selecting both from the dropdown ( https://prnt.sc/kpidqx ) 通过从下拉列表( https://prnt.sc/kpidqx )中选择两者,将该用户添加到您的数据库中
  5. Now, use this username & password to connect with the database. 现在,使用此用户名和密码连接数据库。

mysqli_connect(serverhostname,username,password,dbname);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 mysql_connect()使用什么密码和用户名? - What password and username do I use for mysql_connect()? 如何为mysql创建用户名和密码? - how do i create a username and password for mysql? 尝试连接到 somee.com 数据库时是否使用我的登录用户名和密码? - Do i use my login username and password when trying to connect to a somee.com database? 我需要使用哪个用户名密码登录symfony 2 Admin后端 - Which username password i need to use to login in symfony 2 Admin backend mysql connect - 应该用户名/密码进行硬编码吗? - mysql connect - should username/password be hardcoded? 我如何在不输入任何用户名或密码的情况下连接到mysql? - How am i able to connect to mysql without entering any username or password? mysql服务器,用户名和密码是否在php网站上公开? (的mysql_connect) - Is the mysql server, username and password public on a php website? (mysql_connect) PHP如何从mysql_connect()获取mysql用户名和密码 - PHP how to get mysql username and password from mysql_connect() 我需要关注php中的mysql_connect中的密码吗? - Do I need to be concerned about password in mysql_connect in php? 如何在Windows中使用没有用户名和密码的MySQL连接Laravel应用程序 - How to connect Laravel application with MySQL with no username and password in Windows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM