publiclab / plots2

a collaborative knowledge-exchange platform in Rails; we welcome first-time contributors! :balloon:
https://publiclab.org
GNU General Public License v3.0
957 stars 1.83k forks source link

"mysql2 is not part of bundle" error while running rails server #4936

Open grvsachdeva opened 5 years ago

grvsachdeva commented 5 years ago

Hi!

I updated my local master, ran bundle install and got the below error on running rails s

mysql2_error

I also ran bundle install --without production mysql after deleting Gemfile.lock but got same error.

Solution which worked for me:

I added gem 'activerecord-mysql2-adapter' to the gemfile, deleted Gemfile.lock, ran bundle install, ran rails s and error gone.

Here's a snippet from Gemfile

gemfile

which states running bundle install --without production mysql should not require need to include the activerecord-mysql2-adapter but it didn't worked.

Any idea @jywarren @siaw23 @publiclab/reviewers @publiclab/plots2-reviewers?

@siddhishree has also reported the same error in the Gitter channel:

I've been trying to setup local plots2 development environment while follwing https://github.com/publiclab/plots2#installation, and while on step 7 I face issue https://pastebin.com/AbL6a7Cw, I tried installing mysql2 on gem but no changes, I'm a bit inexperienced in ruby, so if anyone can help

SidharthBansal commented 5 years ago

I am also receiving similar error. Thanks for posting Gaurav.

On Thu, Mar 7, 2019, 9:24 PM Gaurav Sachdeva notifications@github.com wrote:

Hi!

I updated my local master, ran bundle install and got the below error on running rails s

[image: mysql2_error] https://user-images.githubusercontent.com/20878070/53969213-60c72900-411e-11e9-8841-ee7126c55ff7.png

I also ran bundle install --without production mysql after deleting Gemfile.lock but got same error.

Solution which worked for me:

I added gem 'activerecord-mysql2-adapter' to the gemfile, deleted Gemfile.lock, ran bundle install, ran rails s and error gone.

Here's a snippet from Gemfile

[image: gemfile] https://user-images.githubusercontent.com/20878070/53969507-ee0a7d80-411e-11e9-8b46-277b00f09239.png

which states running bundle install --without production mysql should not require need to include the activerecord-mysql2-adapter but it didn't worked.

Any idea @jywarren https://github.com/jywarren @siaw23 https://github.com/siaw23 @publiclab/reviewers https://github.com/orgs/publiclab/teams/reviewers @publiclab/plots2-reviewers https://github.com/orgs/publiclab/teams/plots2-reviewers?

@siddhishree https://github.com/siddhishree has also reported the same error in the Gitter channel:

I've been trying to setup local plots2 development environment while follwing https://github.com/publiclab/plots2#installation, and while on step 7 I face issue https://pastebin.com/AbL6a7Cw, I tried installing mysql2 on gem but no changes, I'm a bit inexperienced in ruby, so if anyone can help

— You are receiving this because you are on a team that was mentioned. Reply to this email directly, view it on GitHub https://github.com/publiclab/plots2/issues/4936, or mute the thread https://github.com/notifications/unsubscribe-auth/AUACQ4pLQHHt60FE6aLHz4Scj-kfnXgjks5vUTYdgaJpZM4bjhXr .

grvsachdeva commented 5 years ago

You can add gem 'activerecord-mysql2-adapter' to Gemfile @SidharthBansal as a temporary fix. Let's see what others think about this fix. Thanks!

siaw23-retired commented 5 years ago

Application is configured to use Passenger. So instead of rails s to start the server you should be running passenger start instead. That way you don't need gem 'activerecord-mysql2-adapter' in the Gemfile.

CleverFool77 commented 5 years ago

I followed your method for temp fix but the error isn't gone.

grvsachdeva commented 5 years ago

Application is configured to use Passenger. So instead of rails s to start the server you should be running passenger start instead. That way you don't need gem 'activerecord-mysql2-adapter' in the Gemfile.

Ah, although I prefer to use Webrick as for development it has been sufficient for me and haven't thrown such error. I also tried passenger but same error

passenger_start

CleverFool77 commented 5 years ago

@gauravano While doing rake:db: setup. It's showing the same error even after adding gem 'activerecord-mysql2-adapter' in Gemfile and deleting lock file and running install bundle.

siaw23-retired commented 5 years ago

There's a bunch of solutions here. I haven't taken time to look into this as I'd have to first but I'm sure the SO thread should have a at least one fix for this that you can try.

cesswairimu commented 5 years ago

Got the same error about two days ago after pulling master. I normally use sqlite3 . Adding gem 'mysql2', '>= 0.4.4' on the list of main gems removed the error for me. Not a smart fix though.

siaw23-retired commented 5 years ago

@cesswairimu i've had 'mysql2', '>= 0.4.4' in the main gem list from the start but don't check it in. That's the main reason I was trying to push for a one-DB system. It's like to work with the project like this...at least for me.

cesswairimu commented 5 years ago

Aha! I see do u use mysql as your local db and if so were you getting this error @siaw23 ?

siaw23-retired commented 5 years ago

I've never seen this error before. Everything works fine for me except the hustle of having to juggle different db systems. So I use mysql (MariaDB variant) for this project and all is fine.

jywarren commented 5 years ago

I seem to remember (but am not sure of it) some PR that may have changed the gemfile's mysql setup recently. I feel like i look at a lot of PRs so I could be mixed up with MapKnitter.

But also it's hard to skim the changes to the Gemfile now because dependabot is helping us update it all the time. Is there a quick commandline way to skim all the diffs to the Gemfile to look for "mysql" and see if anything's changed in the past month or so?

https://github.com/publiclab/plots2/commits/master/Gemfile

On Thu, Mar 7, 2019 at 12:57 PM Cess notifications@github.com wrote:

Got the same error about two days ago after pulling master. I normally use sqlite3 . Adding gem 'mysql2', '>= 0.4.4' on the list of main gems removed the error for me. Not a smart fix though.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/publiclab/plots2/issues/4936#issuecomment-470629456, or mute the thread https://github.com/notifications/unsubscribe-auth/AABfJ239RLdmBQQn-m2-GumqGVQWMoR6ks5vUVLtgaJpZM4bjhXr .

sashadev-sky commented 5 years ago

@siaw23 @cesswairimu I did the same as both of you for a bit and then got rid of it somehow just need to remember exactly what I did! Try putting it back into production, removing activerecord-mysql2-adapter (maybe even uninstall it from the CLI) and deleting the .bundle folder rm -r .bundle and running bundle install again.

@siaw23 I only use rails s and I avoid activerecord-mysql2-adapter completely so I don't know if it has to do with that but I could be wrong it gets difficult to keep track of exactly whats running when.

can someone possibly check if they get it in mapknitter too just to see if its plots2 specific? I may have gotten it and then fixed it there too. I have a pending PR for a mysql update there so I would want to note this issue there

sashadev-sky commented 5 years ago

@jywarren I use the vscode extension GitLens it lets you scroll through the file history of any file going months back. There haven't been any recent changes to mysql in the gemfile

grvsachdeva commented 5 years ago

I use Git blame for checking the history of a file. Works good for me. As Sasha mentioned, there's no change - https://github.com/publiclab/plots2/blame/1678b22d17a6bca4f4320e4efaa79df979ded005/Gemfile#L78

Anyway, I am working by adding activerecord-mysql-adapter for now. I will give try to @siaw23's link, @cesswairimu approach and @sashadev-sky's approach soon.

Thanks all!

madeofhuman commented 5 years ago

I ran into this problem when setting up the repo on my system using sqlite. I tried tracing it to get more details and saw the error Mysql2::Error: The used table type doesn't support FULLTEXT indexes. Tracing that further led me to db/schema.rb:58:


add_index "comments", ["comment"], name: "index_comments_on_comment", type: :fulltext if ActiveRecord::Base.connection.adapter_name == 'Mysql2'

I traced the error further and got to the file config/initializers/abstract_mysql2_adapter.rb. When I commented out the contents of this file and ran rake db:setup again, everything worked fine.

I can raise a PR to fix this, @gauravano.

jywarren commented 2 years ago

Folks are still experiencing this so I'm re-opening and we should try to:

  1. compile working solutions (even if not working for everyone)
  2. organize how to diagnose and what to try (for different environments)
  3. add a link to our READMEs etc to come here (or a fresh issue) to troubleshoot

Thanks all, for helping to figure this out! If you can leave a comment here please note as many of these as you can:

  1. what exactly you experienced (and your environment details: database, OS, versions?)
  2. what you tried from the above solutions if any, and which did or didn't work
  3. please save your full log output in https://gist.github.com/ and share a link here so we can read with full context

Thank you!!!

jywarren commented 2 years ago

OK so the core issue we're focusing on is "mysql2 is not part of bundle" error while running rails server -- which also can occur when running passenger start. If you have a different error or a different but similar variation of this, please let us know with some details!

This does not affect GitPod, so a quick fix is to use GitPod (as in the README) as a workaround.

This has especially affected folks running the app locally. I suspect it may relate to mysql installation on different OS or architectures, or mysql dev files being installed.

I'll start compiling solutions people have tried, and will number them. We'll try to track which have worked for more people, and perhaps see patterns emerge as we get more info from people.

jywarren commented 2 years ago

Solutions:

  1. We saw this resolve for some people after this change was made:

https://github.com/publiclab/plots2/pull/4984/files (runs require 'active_record/connection_adapters/mysql2_adapter' only if ActiveRecord::Base.connection.adapter_name == "Mysql2"

  1. Some people bypassed by using passenger start or the simple webrick server with rails server webrick

  2. Adding gem 'activerecord-mysql2-adapter' to Gemfile

  3. Adding gem 'mysql2', '>= 0.4.4' on the list of main gems in the Gemfile (i.e. outside group :mysql, :production do) (supported by this post saying "make sure that the gem is not placed inside a group statement in your Gemfile") - basically moving that line outside of this block

  4. on debian or ubuntu try sudo apt-get install libmysqlclient-dev and then run bundle install again

  5. Downgrading to gem 'mysql2', '~=0.3.2' or lower -- Historically we had kept mysql gem below v0.4.3 because, according to this note, 0.4.3+ causes a version mismatch, apparently, and demands 'activerecord-mysql2-adapter' -- however, probably due to Dependabot, we eventually went past that to now having v0.5.3 -- since Nov 28, 2019; see Gemfile.lock

Note: this page says:

"It's currently an issue with Rails 4.1.x and 4.2.x, per this bug report, it will be fixed in the next release of rails 4.2.x (credit to dcorr in comments for the link).

But many are experiencing it on Rails 5 now.

stephaniequintana commented 2 years ago

tl;dr I aborted the process of setting up mysql as my database (reasons below), but was still unable to setup the environment due to ???

I do want to preface that my original issue was installing rvm on my Mac w/zsh - it was a tangled mess due to cacertificates and hidden files. I finally found a quick fix so please reach out to me if you're experiencing the same.

It is at (and due to) the following point I decided to abort setting up mysql2 as my database in favor of sqlite3.

Please see here for the full log.

Thanks in advance for any information/advice you may have to help me get set up. Please let me know if I can provide any further information. In the meantime, I'll ensure I'm familiar with the ins/outs of GitPod. Happy coding, everybody!

jywarren commented 2 years ago

Hi @stephaniequintana this is really helpful and thorough note taking, thank you. In sqlite, are you able to run everything normally in development mode, or are you not yet sure of that? We used to use sqlite in development more often, but over time we began using more mysql features such as fulltext searching. However, I believe at least some of those features are isolated with conditionals; this is not super ideal but it works:

https://github.com/publiclab/plots2/blob/e646cfd248e46fe9cf11a2eb7860bbf29f949b7d/db/migrate/20180804042601_add_full_text_index_on_username.rb#L3-L4

That means full text search doesn't work in sqlite but most other things should, i believe.

But, to your specific issues now:

  1. I am looking to clarify why we still need to create the manifest.js file. I noticed we don't do it in the GitPod setup: https://github.com/publiclab/plots2/blob/main/.gitpod.yml so i wonder why it's necessary locally?
  2. the "unauthenticated git protocol" issue you mentioned is unfortunate but unrelated to setup. I'm documenting it in XXX but for now, can you try running git config --global url."https://github.com/".insteadOf ssh://git@github.com/ and then re-running the webpacker command?

Again, thank you! This last issue especially is new and we're working to smooth out the install process given the difficulties. Did you mention btw that you wanted a local copy to be able to run tests? I /believe/ tests will run in gitpod, won't they? Not sure but would be good to know if not. Thank you!!!

stephaniequintana commented 2 years ago

@jywarren To clarify, I wanted to set up my local environment because I thought it was a necessary step in being able to contribute (partly due to link by the welcomebot from my initial PR). Even after learning about GitPod, I was resolved to work through the setup errors, a personal faux pa of determination. Please, do not concentrate any further efforts on getting my personal local environment up and running. I'm glad to be able to gain experience with GitPod.

That said, I would like to help in any way that I can. Please let me know if you would like me to run setup commands or send error logs...

In reference to the above questions, I did not get far enough through the process to see if I could run everything in development mode. I did run git config --global url."https://github.com/".insteadOf ssh://git@github.com/ followed by the webpacker command. It did not solve my issue, here is the error log for your viewing. For fun, I ran passenger start and the following is what http://localhost:3000/ shows:

Screen Shot 2022-03-23 at 11 50 06 AM

I feel as though I opened a few cans of worms for you all, my apologies. Again, I would like to help in any way that I can, please feel free to let me know if or how I might be able to.

jywarren commented 2 years ago

No worries @stephaniequintana it's very helpful to know of these barriers in our install process. I'm going to follow up with the question "is this webpack step necessary for local development" and I think i can research that question.

I found from your very helpful log that the webpack step runs yarn which is why it results in a similar error:

Updating webpack paths to include .jsx file extension
File unchanged! The supplied flag value not found!  config/webpacker.yml
Installing all react dependencies
         run  yarn add react react-dom @babel/preset-react prop-types babel-plugin-transform-react-remove-prop-types from "."
yarn add v1.22.18
[1/4] 🔍  Resolving packages...
error Command failed.
Exit code: 128
Command: git
Arguments: ls-remote --tags --heads git://github.com/jywarren/grow.git
Directory: /Users/stephaniequintana/Desktop/plots2
Output:
fatal: remote error: 
  The unauthenticated git protocol on port 9418 is no longer supported.
Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information.

I'll have to see why the forced protocol change didn't help, but it's very useful info for addressing https://github.com/publiclab/plots2/issues/10827

jywarren commented 2 years ago

Also @stephaniequintana i wanted to point out that I found the webpack steps were not necessary in installation -- see details at https://github.com/publiclab/plots2/issues/10828 but basically the cause of these errors was https://github.com/publiclab/plots2/issues/10827, and once we solve that completely we shouldn't see the webpack error again!

stephaniequintana commented 2 years ago

@jywarren - Thank you for sharing that with me, it absolutely made my day! ...and reading through those comments is like watching rocket surgery (yes, rocket surgery!) - KUDOS to you and @Forchapeatl 🥳 I have now developed knowledge envy.