如何将mysql数据库文件连接到Rails应用程序上的本地ruby

编程入门 行业动态 更新时间:2024-10-24 12:21:28
本文介绍了如何将mysql数据库文件连接到Rails应用程序上的本地ruby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个数据库文件(name.sql)发送给我,我应该连接到本地托管在Mac上的Rails应用程序,该应用程序是我从github下载的(分叉的?).如何设置我的database.yml文件以与sql文件连接.

I have a database file (name.sql) that was sent to me that I am supposed to connect to a rails app locally hosted on my mac, that I downloaded (forked?) from github. How do I set up my database.yml file to connect with the sql files.

推荐答案

您不能将Rails应用程序直接连接到SQL文件. Rails应用程序从数据库服务器获取其数据,然后将SQL文件的内容导入到服务器托管的数据库中.

You can't connect a Rails application directly to a SQL file. The Rails application gets its data from a database server and you import the contents of the SQL file into a database hosted by the server.

您可以下载DMG归档文件,该归档文件将从 http: //dev.mysql/downloads/mysql/#downloads

You can download a DMG archive which will install MySQL Community Server on your Mac from dev.mysql/downloads/mysql/#downloads

该下载文件还包含一个方便的首选项窗格",用于启动和停止服务器.

That download also includes a handy Preference Pane for starting and stopping the server.

一旦启动并运行MySQL,则应使用以下方式为root用户(即数据库系统管理员)设置密码:

Once you have MySQL up and running then you should set a password for the root user (i.e. the database system administrator) using

mysqladmin -u root password "secret"

—显然用您要使用的真实密码替换secret.

—Obviously replace secret with the real password you want to use.

然后,您可以为Rails应用程序设置database.yml文件.对于名为 app 的应用程序,它看起来像这样:

Then you can set up the database.yml file for the Rails application. For an application named app it would look like this:

development: adapter: mysql database: app_development username: root password: secret host: localhost test: adapter: mysql database: app_test username: root password: secret host: localhost production: adapter: mysql database: app_production username: root password: secret host: localhost

请注意,通常在生产环境中,您将为Rails应用程序创建一个单独的受限特权数据库用户帐户,以用于与MySQL连接,但对于在本地计算机上进行开发,root帐户就可以了.

Note that typically in production you'd create a separate limited privilege database user account for the Rails application to connect to MySQL with, but for development on your local machine the root account is fine.

完成此步骤后,您可以从终端机内的Rails应用程序的根目录运行rake db:create.此命令将在MySQL中创建app_development数据库(rake db:create:all也会创建测试数据库和生产数据库).最后,您可以通过在终端中输入以下命令来导入SQL文件:

After this step you can run rake db:create from the root of the Rails application within the Terminal. This command will create the app_development database in MySQL (rake db:create:all creates the test and production databases too). Finally, you can import your SQL file by entering the following command in the Terminal:

mysql -u root -p app_development < path/to/file/name.sql

系统将提示您输入MySQL根密码.如果path/to/file不在终端的当前目录中,请用SQL文件的完整路径替换.例如,如果~/Desktop/name.sql在您的桌面上,则使用它.

You will be prompted for the MySQL root password. Replace path/to/file with the full path to the SQL file if it's not within the Terminal's current directory. For example, use ~/Desktop/name.sql if it's on your desktop.

更多推荐

如何将mysql数据库文件连接到Rails应用程序上的本地ruby

本文发布于:2023-10-25 22:16:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528265.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   如何将   应用程序   数据库文件   ruby

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!