How can I create a new database in vagrant dev environment for testing?

I am trying to test my plugin using the methodology outlined and supported by wp-cli

My tests work fine on previous dev environements, they work fine when doing CI with Travis, but they don’t work using Trellis because I am unable to create the required worpress_test database Ie.

$ vagrant ssh
$ mysqladmin create wordpress_test --user=example_com --password=example_dbpassword --host= --protocol=tcp
> mysqladmin: CREATE DATABASE failed; error: 'Access denied for user 'example_com'@'localhost' to database 'wordpress_test''

(also fails with root:devpw)

I found a comment made by swalkinshaw on Jul 17, 2015 that says this community would be in favour of automatically creating a test db in development… That’s great! I need it. :slight_smile:

For now, how can I create my test db inside the vagrant dev environment to run my tests?

Well you definitely need to use the root user credentials to create it. No specific why that should fail though as long as credentials are correct.

Thanks for the reply, we figured out why it fails:

The workaround is something along the lines of:

$ sudo mysql -u root

mysql> USE mysql;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> exit;

$ service mysql restart
$ mysqladmin create wordpress_test --user=root --password=devpw --host= --protocol=tcp