postlight / headless-wp-starter

🔪 WordPress + React Starter Kit: Spin up a WordPress-powered React app in one step
https://archive.postlight.com/labs/wordpress-react-starter-kit
GNU General Public License v2.0
4.48k stars 649 forks source link

MySQL Access #129

Closed elvinos closed 5 years ago

elvinos commented 6 years ago

Hello,

Great application, looking forward to building some great new projects with this.

Having difficulty accessing the MySQL database, what are the credentials to access it via a tool like sequel pro?

Thanks

modelm commented 6 years ago

If you are using docker, you can access a mysql shell with:

docker exec -it <container> mysql

where <container> is the ID or name of the wp_headless container (which you can find with docker ps).

I don't think there is any way to directly access the mysql service using a tool running outside the container (but if I learn otherwise I'll edit this).

You can expose the container's mysql service on the guest with these changes: https://github.com/postlight/headless-wp-starter/compare/master...modelm:feature-expose-mysql

Then you can connect to mysql from the guest like so: mysql -uroot -h127.0.0.1 wp_headless

annamirakk commented 5 years ago

I have the project installed on my local, but another person will be deploying it. They will have access to the project repository. Do I need to send them my local database in any form?

From what I understand, default ACF values are saved in a JSON file, though regular page content or ACF page-specific overrider are only saved in my local database.

If so, what's the best way to transfer my DB to the person that will be deploying the project? Thank you!

modelm commented 5 years ago

@annamirakk You should ask the person deploying it, it depends on the host and available tools. You could use a plugin like https://wordpress.org/plugins/wp-migrate-db/.

annamirakk commented 5 years ago

@modelm I've tried running both docker exec -it e7de132bce40 mysql and docker exec -it wp-headless mysql from the project root where "e7de132bce40" is the ID and "wp-headless" is the name and both throw an error ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2). Any idea what could be wrong?

modelm commented 5 years ago

@annamirakk The container running mysql is db-headless, not wp-headless, so connect directly there. You must also provide a username & password since the default root is not allowed.

docker exec -it db-headless mysql -uwp_headless -pwp_headless wp_headless

modelm commented 5 years ago

Closing since the original issue is outdated with the Docker updates in https://github.com/postlight/headless-wp-starter/pull/160