在 Ubuntu 上完全从 bash 脚本安装 mysql 5.7
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37806037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
install mysql 5.7 purely from bash script on Ubuntu
提问by tt_Gantz
I want a bash script that installs a MySQL 5.7 instance without needing any manual input.
我想要一个无需任何手动输入即可安装 MySQL 5.7 实例的 bash 脚本。
I was following the tutorial on Digital Oceanand it says for 5.7 you have to run the following commands and then put commands into a prompt (screenshot below).
我正在关注Digital Ocean 上的教程,它说对于 5.7,您必须运行以下命令,然后将命令放入提示中(下面的屏幕截图)。
wget http://dev.mysql.com/get/mysql-apt-config_0.6.0-1_all.deb
sudo dpkg -i mysql-apt-config_0.6.0-1_all.deb
How can I automate the installation if it requires me to use a prompt? Should I try to simulate keystrokes? Or am I going about it the wrong way?
如果需要我使用提示,我该如何自动化安装?我应该尝试模拟击键吗?还是我以错误的方式处理它?
回答by tt_Gantz
This answer is a combination and alteration of Bimmy's and khrm's answers.
这个答案是 Bimmy 和 khrm 答案的组合和改变。
STEP 1:
第1步:
You have to set debconf
values which will automatically fill in the values prompted for by the installation.
您必须设置debconf
值,这些值将自动填充安装提示的值。
export DEBIAN_FRONTEND="noninteractive"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password rootpw"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password rootpw"
export DEBIAN_FRONTEND="noninteractive"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password rootpw"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password rootpw"
To get the values you need, just run installation normally, a good tutorial of it is here
要获得您需要的值,只需正常运行安装即可,这里有一个很好的教程
STEP 2:
第2步:
Update the information needed for APT by adding the 5.7 repository and updating `apt-get
通过添加 5.7 存储库并更新 apt-get 来更新 APT 所需的信息
sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 5072E1F5
cat <<- EOF > /etc/apt/sources.list.d/mysql.list
deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7
EOF
sudo apt-get update
sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 5072E1F5
cat <<- EOF > /etc/apt/sources.list.d/mysql.list
deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7
EOF
sudo apt-get update
STEP 3:
第 3 步:
Install MySQL. You can run my mysql_secure_installation
but then that will ask you for more prompts. mysql_secure_installation
is just a script so if you want to you can just run the parts of that script which are relevant to you.
安装 MySQL。您可以运行 my ,mysql_secure_installation
但随后会要求您提供更多提示。mysql_secure_installation
只是一个脚本,因此如果您愿意,您可以运行该脚本中与您相关的部分。
I just ran
sudo apt-get install -y mysql-server-5.7
on its own.
我只是sudo apt-get install -y mysql-server-5.7
自己跑
。
回答by khrm
You are proceeding in the wrong way. You don't need that package. That package only setup mysql repo.
你以错误的方式进行。你不需要那个包。该软件包仅设置 mysql 存储库。
You need to manually setup the mysql repository if you don't want prompt. Assuming you are using trusty (Ubuntu 14.04):
如果您不想要提示,则需要手动设置 mysql 存储库。假设您使用的是 trusty (Ubuntu 14.04):
sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 5072E1F5
cat <<- EOF > /etc/apt/sources.list.d/mysql.list
deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7
EOF
sudo apt-get update
sudo apt-get install -y mysql-server-5.7
mysql_secure_installation
If you want other stuffs like workbench-6.2, etc. You need to include it like this in file /etc/apt/sources.list.d/mysql.list after the first entry:-
如果你想要其他的东西,比如 workbench-6.2 等,你需要在第一个条目之后将它包含在文件 /etc/apt/sources.list.d/mysql.list 中:-
deb http://repo.mysql.com/apt/ubuntu/ trusty workbench-6.2
回答by aalf1987
I think this linkmay be useful for you. The videoshows the whole process using a previous version (5.6).
我认为此链接可能对您有用。该视频显示了使用先前版本 (5.6) 的整个过程。
To sum up, you should:
总结一下,你应该:
- Export a variable called DEBIAN_FRONTEND with the value "noninteractive".
- Use debconf-set-selections in order to set a root password (for your MySQL Server).
- Install mysql-server-5.7 package.
Run a secure installation afterwards.
export DEBIAN_FRONTEND="noninteractive" sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password rootpw" sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password rootpw" sudo apt-get install -y mysql-server-5.7 mysql_secure_installation
- 导出一个名为 DEBIAN_FRONTEND 的变量,其值为“noninteractive”。
- 使用 debconf-set-selections 来设置 root 密码(用于您的 MySQL 服务器)。
- 安装 mysql-server-5.7 包。
之后运行安全安装。
export DEBIAN_FRONTEND="noninteractive" sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password rootpw" sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password rootpw" sudo apt-get install -y mysql-server-5.7 mysql_secure_installation
NOTE: You can install debconf-utils typing the following command: sudo apt-get install -y debconf-utils
注意:您可以输入以下命令安装 debconf-utils: sudo apt-get install -y debconf-utils