提问人:Chakreshwar Sharma 提问时间:3/15/2022 最后编辑:Chakreshwar Sharma 更新时间:5/2/2022 访问量:1078
在 mac m1 中启动 rails 服务器时出现 Mysql2 错误
Mysql2 error in starting rails server in mac m1
问:
我使用以下命令在 mac m1 中安装了 mysql2
gem uninstall mysql2
gem install mysql2 -v '0.3.21' -- --srcdir=/usr/local/Cellar/mysql/8.0.28_1/bin/include --with-mysql-include=/usr/local/Cellar/mysql/8.0.28_1/include/mysql --with-mysql-lib=/usr/local/Cellar/mysql/8.0.28_1/lib --with-cppflags=-I/usr/local/opt/[email protected]/include --with-opt-dir=/usr/local/opt/[email protected] --platform=ruby
安装有效,但是当我开始时,出现以下错误rails s
/gems/mysql2-0.3.21/lib/mysql2.rb:31:in `require': cannot load such file -- mysql2/mysql2 (LoadError)
我正在使用 和Rails 3.2.22.5
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin21]
我将openssl降级为使用rosetta安装ruby 2.3.01.0
我已经使用 安装了 mysql8。brew install mysql
上面在我的另一个项目中工作,该项目在 Rails 4.2 和 Ruby 2.3.1 上运行,但不知道为什么它在这里不起作用。
我还尝试将mysql8降级到5.7,然后使用以下命令安装mysql2
gem install mysql2 -v 0.3.21 -- --with-mysql-config=/usr/local/Cellar/[email protected]/5.7.37/bin/mysql_config --srcdir=/usr/local/Cellar/[email protected]/5.7.37/bin/include --with-ldflags=-L/usr/local/opt/[email protected]/lib --with-cppflags=-I/usr/local/opt/[email protected]/include --platform=ruby
但同样的错误,安装完成,但加载错误rails s
任何修复此错误的帮助将不胜感激。
答:
0赞
Chakreshwar Sharma
3/22/2022
#1
我可以通过将mysql降级到5.7然后安装来解决此问题 [EMAIL PROTECTED]
步骤如下:
#stop mysql
brew services stop mysql
# install mysql5.7
brew install [email protected]
#Link mysql5.7
brew unlink mysql
brew link [email protected] --force
# install mysqlclient
brew install [email protected]
#uninstall old mysql versions if already installed
gem uninstall mysql2
#install mysql2
gem install mysql2 -v 0.3.21 -- --with-mysql-config=/usr/local/bin/mysql_config --with-ldflags=-L/usr/local/Cellar/[email protected]/1.0.2u/lib --with-cppflags=-I/usr/local/Cellar/[email protected]/1.0.2u/include
0赞
Nguyễn Viết Thái
5/2/2022
#2
试试这种方式,对我有用
brew install openssl zstd mysql
LIBRARY_PATH=$(brew --prefix zstd)/lib/:$(brew --prefix openssl)/lib/ gem install mysql2
评论
gem install activerecord-mysql2-adapter