我像这样在 CentOS 7 (x64) 上安装 MySQL 5.7:
yum localinstall -y https://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm;
yum install -y mysql-community-server;
新版mysql自动生成随机root密码。这可以通过以下命令找到:
grep '为 root@localhost 生成临时密码'/var/log/mysqld.log |尾部-1
例如输出:
2016-01-01T20:51:50.861279Z 1 [Note] A temporary password is generated for root@localhost: s8,arY7l_xQ:
有没有办法将随机生成的根传递 s8,arY7l_xQ:
解析为上述命令输出中的变量?
最佳答案
这似乎对我有用:
dan@ebony ~ $ cat file
2016-01-01T20:51:50.861279Z 1 [Note] A temporary password is generated for root@localhost: s8,arY7l_xQ:
dan@ebony ~ $ grep 'temporary.*root@localhost' file | sed 's/.*root@localhost: //'
s8,arY7l_xQ:
dan@ebony ~ $ passwd="`grep 'temporary.*root@localhost' file | sed 's/.*root@localhost: //'`"
dan@ebony ~ $ echo $passwd
s8,arY7l_xQ:
关于mysql - 在 bash shell 脚本中解析 MySQL Community Edition 5.7 自动生成的临时 root 密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34560031/