I am having trouble getting my database to connect in wamp. It's been about 5 years since i've done this so i'm a little rusty. I upgraded my Mysql to 8.0 and I came across the error
Fatal error: Uncaught PDOException: PDO::__construct(): The server requested authentication method unknown to the client [sha256_password] in C:\wamp64\www\dirtyosrs\assets\lib\core\Database.class.php:34 Stack trace: #0 C:\wamp64\www\dirtyosrs\assets\lib\core\Database.class.php(34): PDO->__construct('mysql:host=;dbn...', NULL, NULL, Array) #1 C:\wamp64\www\dirtyosrs\assets\lib\init.php(34): Database->connect() #2 C:\wamp64\www\dirtyosrs\templates\header.php(8): require_once('C:\\wamp64\\www\\d...') #3 C:\wamp64\www\dirtyosrs\index.php(1): include('C:\\wamp64\\www\\d...') #4 {main} Next PDOException: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client in C:\wamp64\www\dirtyosrs\assets\lib\core\Database.class.php on line 34
PDOException: PDO::__construct(): The server requested authentication method unknown to the client [sha256_password] in C:\wamp64\www\dirtyosrs\assets\lib\core\Database.class.php on line 34
I flushed my privileges and changed the plugin to native on root. i'm stumped at this point. could someone help me?
here is my database class up to line 37
<?php
/**
Class Database
*/
class Database {
private $IP, $username, $password, $database;
/**
#var PDO
*/
private $connection;
private $query = 0;
/**
Database constructor.
#param $IP
#param $username
#param $password
#param $database
*/
public function __construct($IP, $username, $password, $database) {
$this->IP = $IP;
$this->username = $username;
$this->password = $password;
$this->database = $database;
}
/**
Attempts to connect to the host
*/
public function connect() {
$this->connection = new PDO('mysql:host='.$this->IP.';dbname='.$this->database.';charset=utf8', $this->username, $this->password, array(PDO::ATTR_PERSISTENT => true));
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
Mysql 8 has since 2018 a new default type of secure authentication method (sha2) that can be hard to get to work on localhost. In order to continue to use the traditional auth method, I do it like this in my Dockerfile:
command: --default-authentication-plugin=mysql_native_password
If you set up manually you have to run the default-authentication command on your database setup.
More info here: https://mysqlserverteam.com/upgrading-to-mysql-8-0-default-authentication-plugin-considerations/
Related
This question already has answers here:
PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client [duplicate]
(8 answers)
Laravel: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
(10 answers)
Closed 1 year ago.
I got an error when I'm migrating. I already create the database Book_Store
here is the .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=Book_Store
DB_USERNAME=root
DB_PASSWORD=
Here is the migration
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCategoriesTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->id(20);
$table->string('category', 255);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('categories');
}
}
Here are the error that I got
Illuminate\Database\QueryException
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = Book_Store and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:703
699▕ // If an exception occurs when attempting to run a query, we'll format the error
700▕ // message to include the bindings with SQL, which will make this exception a
701▕ // lot more helpful to the developer instead of just the database's errors.
702▕ catch (Exception $e) {
➜ 703▕ throw new QueryException(
704▕ $query, $this->prepareBindings($bindings), $e
705▕ );
706▕ }
707▕ }
+33 vendor frames
34 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
I have no idea why I got this error, I have make the database and make sure in .env the name is correct, I've also try to change the host to localhost but it's still showing the error.
I'm trying to connect to my MySQL DB located on 192.168.23.140 from my Web Frontend on .23.139
Here is my code :
$servername = "192.168.23.140";
$username = "web";
$password = "rootnetwork";
$dbname = "test";
try {
$conn = new PDO('mysql:host=$servername; dbname=$dbname', $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
Here is what i get :
Connection failed: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
I've been looking for some answers on the internet but none of them work.
Thank you for your help
$variables are not expanded in a single quotes string literal, they are only expanded in a double quoted string literals.
So
$conn = new PDO("mysql:host=$servername; dbname=$dbname", $username, $password);
You will also have to make sure that this MYSQL user account web is setup to allow connections from ip addresses that are not the ip of the machine running MySQL
I need to establish an SSL connection between MySQL server and PHP web application.
Currently we are working with offline server (wampserver) and we need to establish an SSL connection. Th moment I changed the connection script from:
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->exec("SET CHARACTER SET utf8mb4");
To:
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass, array(
PDO::MYSQL_ATTR_SSL_KEY =>'/etc/mysql/ssl/client-key.pem',
PDO::MYSQL_ATTR_SSL_CERT=>'/etc/mysql/ssl/client-cert.pem',
PDO::MYSQL_ATTR_SSL_CA =>'/etc/mysql/ssl/ca-cert.pem'
));
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->exec("SET CHARACTER SET utf8mb4");
an error appeared on the login page saying:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2006] MySQL server has gone away' in C:\wamp64\www\
EDIT
I run this query:
show variables like '%ssl%'
And got the following result:
There's a lot of documentation on this but my troubleshooting has failed. I installed XAMPP for Windows which works fine but it is not working for my Mac OS Sierra.
My XAMPP version is 5.6.30-0 and my servers are running.
This is my wp-config.php details:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', ‘WP’);
/** MySQL database username */
define('DB_USER', ‘admin’);
/** MySQL database password */
define('DB_PASSWORD', ‘darkall’);
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
The user "admin" is a new user I created just for the "WP" database in phpMyAdmin. WP database exists in phpMyAdmin
I tried to go to http://localhost/wp/ but get the error "Error establishing a database connection""
i think two problems may occur this problem:
1: Adding curly braces to your db name , db username , db password .. Replace them with ' ' single quotion mark.
2: The database username or password is not matching. Recheck the username and password of your database or reset user credentials and go with default username 'root' with empty password Like below :
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'WP');
/** MySQL database username */
define('DB_USER', ‘root’);
/** MySQL database password */
define('DB_PASSWORD', '');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
You can also check database credentials using php db connection .. create a file called conn.php and add below codes to your file :
<?php
$servername = "localhost";
$username = "admin";
$password = "darkall";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
If browser print "Connected successfully" then wordpress should work with this also.
I am using Symfony 3.0.4. I have the error
[2016-05-20 08:50:26] request.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException: "An exception occured in driver: SQLSTATE[HY000] [2002] No route to host" at /var/www/WebProduction/products.markettraders.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 103 {"exception":"[object] (Doctrine\\DBAL\\Exception\\ConnectionException(code: 0): An exception occured in driver: SQLSTATE[HY000] [2002] No route to host at /var/www/WebProduction/products.markettraders.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:103, Doctrine\\DBAL\\Driver\\PDOException(code: 2002): SQLSTATE[HY000] [2002] No route to host at /var/www/WebProduction/products.markettraders.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:47, PDOException(code: 2002): SQLSTATE[HY000] [2002] No route to host at /var/www/WebProduction/products.markettraders.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43)"} []
[2016-05-20 08:50:26] security.DEBUG: Stored the security token in the session. {"key":"_security_main"} []
This is strange because the indexAction is working perfectly, only the Edit Action is NOTWorking, on all of my edit routes. There have been no changes in the code to cause this to happen.
What have I inadvertantly changed in my MySQL configuration that allows Doctrine to find everything on the indexAction but then error out on the editAction?
EDIT
Forgive me.... The code is below. It works in my local environment. It does not work in prod. The error above comes from the prod.log.
In addition the indexAction controller works as well.
/**
* Displays a form to edit an existing AOD Technical Analysis page entity.
*
* #Route("/{id}/edit", name="aod_technical_analysis_edit")
* #Method({"GET", "POST"})
*/
public function editAction(Request $request, AodTechnicalAnalysis $aod_tech)
{
$deleteForm = $this->createDeleteForm($aod_tech);
$editForm = $this->createForm('AppBundle\Form\AodTechnicalAnalysisType', $aod_tech);
$editForm->remove('currencypair');
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($aod_tech);
$em->flush();
$session = $request->getSession();
$message = 'The change was succesfully saved for ' . $aod_tech->getCurrencypair();
$session->getFlashBag()->add('success', $message);
return $this->redirectToRoute('aod_technical_analysis_index');
}
return $this->render('aod_tech/edit.html.twig', array(
'aod_tech' => $aod_tech,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
Have you tried appending "app_dev.php" on your URL to get the debug web toolbar? I have found this to be more helpful compared to logs. You might need to edit the "web/app_dev.php" to add your browser's IP address.