I'm following the plugin test setup/install instructions. I got wp scaffold plugin-tests my-plugin
to run. But then at the next step when I try to run bash bin/install-wp-tests.sh wordpress_test root '' localhost latest
I get the following error:
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to MySQL server on 'localhost' (61)'
Check that mysqld is running on localhost and that the port is 3306.
You can check this by doing 'telnet localhost 3306'
My local Wordpress site is running with MAMP (which is working). I'm not sure if that's relevant for the install script since I think it's creating a temporary DB to run the tests... Does it matter if it uses the built-in OSX mysql or MAMP's MySQL?
Here's the output from wp --info
$ ./vendor/wp-cli/wp-cli/bin/wp --info
PHP binary: /Applications/MAMP/bin/php/php5.6.10/bin/php
PHP version: 5.6.10
php.ini used: /Applications/MAMP/bin/php/php5.6.10/conf/php.ini
WP-CLI root dir: /Applications/MAMP/htdocs/pipeline/wp-content/plugins/wp-github-pipeline/vendor/wp-cli/wp-cli
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 0.19.2
Update 2 I figured out that originally MySQL wasn't installed... that's why I couldn't connect! But now it is. I ran the install script, and this works...
$ ./vendor/wp-cli/wp-cli/bin/wp db tables
wp_users
wp_usermeta
wp_posts
wp_comments
wp_links
wp_options
wp_postmeta
wp_terms
wp_term_taxonomy
wp_term_relationships
wp_commentmeta
But when I run phpunit
I get this:
$ phpunit
PHP Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452
PHP Stack trace:
PHP 1. {main}() /private/tmp/wordpress-tests-lib/includes/install.php:0
PHP 2. require_once() /private/tmp/wordpress-tests-lib/includes/install.php:21
PHP 3. require_wp_db() /private/tmp/wordpress/wp-settings.php:79
PHP 4. wpdb->__construct() /private/tmp/wordpress/wp-includes/load.php:350
PHP 5. wpdb->db_connect() /private/tmp/wordpress/wp-includes/wp-db.php:649
PHP 6. mysqli_real_connect() /private/tmp/wordpress/wp-includes/wp-db.php:1452
Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452
Part of my problem is that I'm not clear on whether wp-cli should be running entirely on native (cli) PHP/Mysql, or MAMP's PHP/Mysql, or some combination of both.
Update 4 I'm pretty sure the final problem is that phpunit needs to be installed in MAMP, but I'm running it from OSX...
$which phpunit
/usr/bin/phpunit
Mentioned in this gist.
Update 6
It turns out you can no longer install phpunit using pear. So I added it as a composer dependency under require-dev, but when I run that version I get the same error!
$ ./vendor/phpunit/phpunit/phpunit
PHP Warning: mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452
PHP Stack trace:
PHP 1. {main}() /private/tmp/wordpress-tests-lib/includes/install.php:0
PHP 2. require_once() /private/tmp/wordpress-tests-lib/includes/install.php:21
PHP 3. require_wp_db() /private/tmp/wordpress/wp-settings.php:79
PHP 4. wpdb->__construct() /private/tmp/wordpress/wp-includes/load.php:350
PHP 5. wpdb->db_connect() /private/tmp/wordpress/wp-includes/wp-db.php:649
PHP 6. mysqli_real_connect() /private/tmp/wordpress/wp-includes/wp-db.php:1452
Warning: mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452
I even added it to my path to be sure...
$ which phpunit
/Applications/MAMP/htdocs/pipeline/wp-content/plugins/wp-github-pipeline/vendor/phpunit/phpunit/phpunit
Update 7
After reading the comments at the bottom of this blog post, I see that the install script was referencing the OSX version of mysqladmin
. I'm not sure if this matters, but I prepended MAMPs version in the path, and re-ran the install script. It seems to install the Wordpress files in /tmp/
anyway. Same error when I run phpunit
telnet localhost 3306
? – Mildredtelnet
to the question above. – Grodnomysql
is being used. Did you try exporting MAMP'smysql
andmysqladmin
as described here? https://mcmap.net/q/122627/-how-to-override-the-path-of-php-to-use-the-mamp-path – Carnyps aux | grep sql
. Furthermore with this command you can check what runs on which port:lsof -i -P | grep -i "listen"
. If mysql is running on the correct port, do you have perhaps a firewall which gets into your way? Ohter option, can you connect to mysql if you run the commandmysql -uroot -p
in the terminal? – Virtuallylocalhost:3306
in the browser I get "Page not found: connection refused" – Grodnops
commands states that mysql is running, but at thelsof
command no port 3306 is available, which is strange. The latter can explain themysql
command error. It seems that mysql is not listening on port 3306, so your connection tries on port 3306 does not work. What doesmysqladmin -u root -p status
give you back. Have a look at/Applications/MAMP/logs/mysql_error_log.err
and/Applications/MAMP/tmp/mysql/my.cnf
perhaps you find there something strange... – Virtuallyps
command you have 2 times mysql running:/Applications/MAMP/Library/bin/mysqld
and/Applications/MAMP/Library/bin/mysqld_safe
. I am not sure if this is correct. In my opinion it should only be one – Virtuallylocalhost
or an IP address? – Clementina