我正在学习ansible,基本上是用ansible设置ec2服务器,并在另一台ec2服务器上安装mysql。目的是创建一个密码为12345的用户Bob。
- hosts: database
sudo: yes
tasks:
- name: Install mySQL repo
yum: name=http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm state=present
- name: Install mySQL
yum: pkg={{ item }}
with_items:
- mysql-community-server
- mysql-community-client
- MySQL-python
- name: start mySQL service
action: service name=mysqld state=started
- name: copy my.cnf
template: src=.my.cnf dest=/root/.my.cnf owner=root mode=0600
- name: Create database user
mysql_user: name=bob password=12345 priv=*.*:ALL state=present login_user=root login_password=Password123_#
这是my.cnf文件:
[client]
user=root
password=Password123_#
当前,这是我完成的剧本,但我不断收到
fatal: [FAILED! => {"changed": false, "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (1045, \"Access denied for user 'root'@'localhost' (using password: NO)\")"}
to retry, use: --limit @/etc/an
请问我在做什么错?
PS:我不是mySQL专家,但我正在学习。
答案 0 :(得分:1)
您要尝试的是为没有mysql连接凭据的新用户定义凭据。
如here所述,void moveDisk(vector<int> &startPeg, vector<int> &goalPeg)
{
// if (goalPeg.size() == 0) better only do that if
if(startPeg.size() > 0)
{
int temp = startPeg.back(); // would fail otherwise
startPeg.pop_back();
goalPeg.push_back(temp);
}
}
int hanoi(int diskNum, vector<int> &startPeg, vector<int> &goalPeg, vector<int> &tempPeg)
{
int count = 0;
if (diskNum == 0)
{
// moveDisk(startPeg, goalPeg); you want to do absolutely nothing
// when there are no discs.
}
else
{
count = hanoi(diskNum - 1, startPeg, tempPeg, goalPeg);
moveDisk(startPeg, goalPeg);
count++;
count += hanoi(diskNum - 1, tempPeg, goalPeg, startPeg);
}
return count;
}
int main()
{
// ...
// int moveCount = hanoi(diskNum, startPeg.peg, tempPeg.peg, goalPeg.peg);
// folowing the paramter names of your hanoi() it should be:
int moveCount = hanoi(diskNum, startPeg.peg, goalPeg.peg, tempPeg.peg);
// ...
}
和login_user
或文件login_password
中的凭据是使用~/.my.cnf
模块添加或删除用户所必需的。
传递凭据时需要登录密码和登录用户。如果不存在该模块,则该模块将尝试从〜/ .my.cnf中读取凭据,最后退回到使用MySQL默认登录名“ root”而不输入密码。