简单步骤
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