【问题标题】:MySQL issues when setting up a VM with Vagrant/chef-solo on OS X在 OS X 上使用 Vagrant/chef-solo 设置 VM 时出现 MySQL 问题
【发布时间】:2013-09-16 05:11:13
【问题描述】:

我在运行 Mountain Lion 的 MBP 笔记本电脑上安装了 VirtualBox、Vagrant 和 chef-solo。我已经从 opscode 下载了食谱,并且“vagrant up”正在工作。 VM 已成功创建,我得到了一个主要工作的 LAMP 堆栈。

我被困在哪里是创建一个数据库和用户来访问数据库。

我做了什么: 创建了一个开发文件夹,其中包含 Vagrantfile 和目录说明书。在我的食谱中

README.md
apache2
apt
aws
build-essential
database
hnnapp
mysql
openssl
php
postgresql
xfs
xml

'hnnapp' 包含我自己的启动虚拟机的方法。我用刀初始化文件夹,然后编辑 metadata.rb 以包含

depends "apt"
depends "apache2"
depends "database"
depends "mysql"
depends "xml"
depends "openssl"
depends "php"
depends "build-essential"

在 recipes/default.rb 我已经包含了

include_recipe "apt"
include_recipe "apache2"
include_recipe "xml"
include_recipe "openssl"
include_recipe "database::mysql"
include_recipe "mysql"
include_recipe "mysql::client"
include_recipe "mysql::server"
include_recipe "mysql::ruby"
include_recipe "php"
include_recipe "php::module_mysql"
include_recipe "apache2::mod_php5"
include_recipe "apache2::mod_rewrite"

apache_site "default" do
    enable true
end

mysql_database node['hnnapp']['database'] do
    connection  ({:host => 'localhost', :username => 'root', :password => node['mysql']['server_root_password']})
    action :create
end

mysql_database_user node['hnnapp']['db_username'] do
    connection  ({:host => 'localhost', :username => 'root', :password => node['mysql']['server_root_password']})
    password node['hnnapp']['db_password']
    database_name node['hnnapp']['database']
    privileges [:select, :update, :insert, :cretae, :delete]
    action :create
end

最后,我的 Vagrantfile 包括

config.vm.provision :chef_solo do |chef|
    chef.add_recipe "hnnapp"
    chef.json = {
      "hnnapp" => {
        "db_password" => "test", 
        "db_username" => "testuser",
        "database" => 'testdatabase'
      },
      "mysql" => {
        "server_root_password" => "098f6bcd4621d373cade4e832627b4f6",
        "server_debian_password" => "098f6bcd4621d373cade4e832627b4f6",
        "server_repl_password" => "098f6bcd4621d373cade4e832627b4f6"
      }
    }
  end

当我“vagrant ssh”进入虚拟机时,我看到安装了 apache、php 和 mysql。 MySQL 除了测试和信息模式之外没有其他数据库。我可以使用 'mysql' 进入 mysql 客户端,但我没有创建任何数据库或用户的权限。 sudo mysql 也不起作用。

我想知道两件事:

  1. 我这样做是否正确?将正确的命令放入正确的文件中?
  2. 我的脚本中有哪些错误。

【问题讨论】:

    标签: mysql macos vagrant chef-solo


    【解决方案1】:

    如果您在 mysql_database_user 块中添加 :grant 到您的操作中会有什么不同吗?

    action [:create, :grant]

    我发现本教程对使用用户和权限配置 mysql 非常有帮助,尽管我仍然对 chef-solo 的目录结构有些困惑。

    http://misheska.com/blog/2013/06/23/getting-started-writing-chef-cookbooks-the-berkshelf-way-part2/

    【讨论】:

    • 感谢您的回答。这没有什么区别,但在尝试之后我注意到我的权限有一个错字。 :( cretae 显然是不正确的。在运行寻求帮助之前,我必须更加小心地重新阅读我的文字。谢谢!
    • 但是,删除权限 [:select, :update, :insert, :cretae, :delete] 并添加您的行确实允许我连接到正确的使用。所以部分你的答案是正确的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多