PHP MySql (1045) Access Denied For User

后端 未结 4 1371
轻奢々
轻奢々 2020-12-07 02:51

I\'ve tried to search for an existing answer to this problem, but the answers I find have not worked thus far.

I\'ve been attempting to use PHP to connect to a MySql

相关标签:
4条回答
  • 2020-12-07 03:07

    check the database name spelling at your phpMyAdmin. Usually the name is in format user_dbname.

    For example:

    cpanel username: jack,  
    database created: student
    

    In your php script, the dbname should be jack_student

    0 讨论(0)
  • 2020-12-07 03:07

    This worked for me:

    • Depending on what MySQL version you have, make sure you have matching password and hostname on your PHP file, config.inc.php file.

    If you need to change the password for MySQL 5.7.6 and later:

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
    

    MySQL 5.7.5 and earlier:

    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
    
    • If you are trying to access your localhost server from a different machine i.e. (emulator, another computer), make sure you are using the actual IP address of the the localhost, DO NOT USE localhost as the hostname. Because this is like telling the machine to connect to itself - but the server is on a different IP address.
    0 讨论(0)
  • 2020-12-07 03:22

    In cPanel, make sure that:

    1. The database user cPanelUsername_dbName exists, with the password dbPassword
    2. The database you want to use exists.
    3. The user cPanelUsername_dbName is allowed to access the database.
    4. The user cPanelUsername_dbName is allowed to access the database from localhost, 127.0.0.1, and the IP address of your server.

    Your MySQL connections may use 127.0.0.1 or the IP address of your server, and MySQL will reject the connection if access isn't granted for the specific IP address used.

    0 讨论(0)
  • 2020-12-07 03:24

    First check the database that you gave the proper user access to your database, which is given from Add User to databases from Mysql database section in cpanel.

    after that check it again,

    first try normal connection code in php,

    $con = mysql_connect("localhost","cpanel_username","cpanel_password");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    
    0 讨论(0)
提交回复
热议问题