0

I am trying to create a mysql database using php. here is the code:

$servername = "localhost";
$username = "root";
$password = "XXXXXXXX";

// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

// Create database
$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
    echo "Database created successfully";
} else {
    echo "Error creating database: " . $conn->error;
}

$conn->close();

here is the error:

Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'root'@'localhost' (using password: YES) in /home/XXXXXXX/public_html/phpinfo.php on line 10 Connection failed: Access denied for user 'root'@'localhost' (using password: YES)

any ideas?

chris85
  • 23,255
  • 7
  • 28
  • 45
Jason
  • 937
  • 15
  • 31

1 Answers1

0

follow this steps :-

Step # 1 : Stop mysql service

/etc/init.d/mysql stop

Step # 2: Start to MySQL server w/o password:

mysqld_safe --skip-grant-tables &

Step # 3: Connect to mysql server using mysql client:

mysql -u root

Step # 4: Setup new MySQL root user password mysql> use mysql;

mysql>

update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';

mysql>

flush privileges;

mysql> quit

Step # 5: Stop MySQL Server:

/etc/init.d/mysql stop

Step # 6: Start MySQL server and test it

/etc/init.d/mysql start

mysql -u root -pNEW-ROOT-PASSWORD
Ahmed farag mostafa
  • 2,248
  • 1
  • 12
  • 31