Asked  7 Months ago    Answers:  5   Viewed   37 times

I just wiped my Mac and did a fresh install of El Capitan. I'm struggling to connect to Mysql now. Having gone through a web server setup process, I've created a simple PHP test file:

<?php
  $conn = new mysqli("127.0.0.1", "root", "xxxxxxxx");
  if ($conn->connect_error) echo "Connection failed: " . $conn->connect_error; 
  else echo "Connected successfully";
  phpinfo();
?>

When I run it, I get this error:

Warning: mysqli::mysqli(): (HY000/1862): Your password has expired. To log in you must change it using a client that supports expired passwords. in /Users/rich/Documents/DESIGN/test/index.php on line 3
Connection failed: Your password has expired. To log in you must change it using a client that supports expired passwords.

I've never seen that response from a connection before. How do I fix it if I can't connect?

EDIT

In terminal I entered the command:

mysql -u root -p

This asked me for my password (current one) which I put in. I now have access to mysql commands but anything I try results in this error:

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

How do I reset the password using ALTER USER?

 Answers

91

So I finally found the solution myself.

Firstly I went into terminal and typed:

mysql -u root -p

This asked for my current password which I typed in and it gave me access to provide more mysql commands. Anything I tried from here gave this error:

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

This is confusing because I couldn't actually see a way of resetting the password using ALTER USER statement, but I did find another simple solution:

SET PASSWORD = PASSWORD('xxxxxxxx');

Wednesday, March 31, 2021
 
mdevils
answered 7 Months ago
61

Open a good text editor (I'd recommend TextMate, but the free TextWrangler or vi or nano will do too), and open:

/etc/apache2/httpd.conf

Find the line:

"#LoadModule php5_module        libexec/apache2/libphp5.so"

And uncomment it (remove the #).

Download and install the latest MySQL version from mysql.com. Choose the x86_64 version for Intel (unless your Intel Mac is the original Macbook Pro or Macbook, which are not 64 bit chips. In those cases, use the 32 bit x86 version).

Install all the MySQL components. Using the pref pane, start MySQL.

In the Sharing System Pref, turn on (or if it was already on, turn off/on) Web Sharing.

You should now have Apache/PHP/MySQL running.

In 10.4 and 10.5 it was necessary to modify the php.ini file to point to the correct location of mysql.sock. There are reports that this is fixed in 10.6, but that doesn't appear to be the case for all of us, given some of the comments below.

Wednesday, March 31, 2021
 
juanrpozo
answered 7 Months ago
73

Assuming you have a good reason to use two different databases, the only way to make this work with a single connection is with a user that has privileges to access both databases. It would go something like this:

$db = new mysqli($host,$user,$pass); // connect to the MySQL server without specifying a database

mysqli_select_db('databaseA', $db); // Specify your default/most-used database

If you don't explicitly specify databaseB in your query, MySQL will use the default (databaseA). So a query that gets one column from databaseB and two from databaseA would look like this:

$query = "SELECT databaseB.table.column, table.column, table.column2";
Wednesday, March 31, 2021
 
Hugo
answered 7 Months ago
94

Try this:

mysql -u root -h 127.0.0.1 -p
Enter password: (enter the random password here)

Ref:https://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization-mysqld.html

Following this, you may reset your password using ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-password';

Monday, June 28, 2021
 
VostanAzatyan
answered 4 Months ago
57

I've had this problem before. ConnectTimeout property only applies to time outs that occur when connecting to the database, not for queries.

CommandTimeout however specifies how long it should wait for the query to return. I believe the default is 30 seconds. Double check the documentation for your MySql library, but for SqlCommand the CommandTimeout is in Seconds not milliseconds.

Saturday, October 9, 2021
 
benjisail
answered 2 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share