rails使用mysql数据库

简单步骤
1,安装mysql
安裝 MySQL
Ubuntu 上安裝 MySQL 請執行:
$ sudo apt-get install mysql-server mysql-common mysql-client libmysqlclient-dev
安裝 MySQL Adapter :
$ gem install mysql2
修改 Gemfile 加上:
gem 'mysql2'
修改 config/database.yml 設定檔。

 常用命令:

  show databases;

  use gold;

  show tables;

 
  
其他文章:参考:http://www.linuxidc.com/Linux/2016-07/133128.htm

  sudo netstat -tap | grep mysql

  通过上述命令检查之后,如果看到有mysql 的socket处于 listen 状态则表示安装成功。

  登陆mysql数据库可以通过如下命令:mysql -u root -p

  -u 表示选择登陆的用户名, -p 表示登陆的用户密码,上面命令输入之后会提示输入密码,此时输入密码就可以登录到mysql。

   其他命令:sudo service mysql restart

 

 

2,修改config/database.yml 配置使用哪个数据库
development:&mysql-setting
adapter: mysql2
encoding: utf8
reconnect: false
database: god
pool: 10
username: root 
password: "znnn"
host: localhost
 
  

default: &default
adapter: sqlite3
pool: 5
timeout: 5000

 
  

development:
<<: *default
database: db/development.sqlite3

 
  

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3

 
  

production:
<<: *mysql-setting

 

新建mysql rails项目

参考 https://www.digitalocean.com/community/tutorials/how-to-use-mysql-with-your-ruby-on-rails-application-on-ubuntu-14-04

1.rails new <app_name> -d mysql 

   2.Configure Database Connection

If you followed the MySQL install instructions from this tutorial, you set a password for MySQL's root user. The MySQL root login will be used to create your application's test and development databases.

Open your application's database configuration file in your favorite text editor. We'll use vi:

vi config/database.yml

Under the default section, find the line that says "password:" and add the password to the end of it. It should look something like this (replace the highlighted part with your MySQL root password):

password: mysql_root_password

  3.Create Application Databases

Create your application's development and test databases by using this rake command:

rake db:create

ubuntu安装mysql可视化工具MySQL-workbench及简单操作

http://blog.csdn.net/jgirl_333/article/details/48575281 

 

mysql 问题

dpkg: error processing mysql-server (--configure)

 

解决方法:

删除mysql前 先删除一下 /var/lib/mysql 还有 /etc/mysql

sudo rm /var/lib/mysql/ -R

sudo rm /etc/mysql/ -R

转载于:https://www.cnblogs.com/znsongshu/p/6767874.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值