Are you just making the connection or are you running a query too?
The code below performs the connection and checks if there was an error, in case of an error it will show the error message and end, in case of success in the connection it will show the success message and then close the connection with the base of data.
<?php
$link = mysqli_connect("HOST", "USUARIO", "SENHA", "BASE");
if (!$link) {
echo "Error: Falha ao conectar-se com o banco de dados MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Sucesso: Sucesso ao conectar-se com a base de dados MySQL." . PHP_EOL;
mysqli_close($link);
Update
Follow the steps in order:
1 - end mysql:
sudo /usr/local/mysql/support-files/mysql.server stop
2 - Start it in safe mode:
sudo mysqld_safe --skip-grant-tables
3 - This will be a continuous command until the process finishes, then open another shell / terminal window and log in without a password as root:
mysql -u root
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NOVASENHA';
Change NOVASENHA to a desired password and start MySQL
sudo /usr/local/mysql/support-files/mysql.server start