本文翻译自:Install MySQL on Ubuntu without a password prompt

How do I write a script to install MySQL server on Ubuntu? 如何编写脚本在Ubuntu上安装MySQL服务器?

sudo apt-get install mysql will install, but it will also ask for a password to be entered in the console. sudo apt-get install mysqlsudo apt-get install mysql ,但它也会要求在控制台中输入密码。

How do I do this in a non-interactive way? 我如何以非交互方式执行此操作? That is, write a script that can provide the password? 也就是说,编写一个可以提供密码的脚本?

#!/bin/bash
sudo apt-get install mysql  # To install MySQL server# How to write script for assigning password to MySQL root user
# End

#1楼

参考:https://stackoom.com/question/WTQz/在没有密码提示的情况下在Ubuntu上安装MySQL


#2楼

Another way to make it work: 使其工作的另一种方法:

echo "mysql-server-5.5 mysql-server/root_password password root" | debconf-set-selections
echo "mysql-server-5.5 mysql-server/root_password_again password root" | debconf-set-selections
apt-get -y install mysql-server-5.5

Note that this simply sets the password to "root". 请注意,这只是将密码设置为“root”。 I could not get it to set a blank password using simple quotes '' , but this solution was sufficient for me. 我无法使用简单的引号''设置空白密码,但这个解决方案对我来说已经足够了。

Based on a solution here . 基于这里的解决方案。


#3楼

Use: 使用:

sudo DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-serversudo mysql -h127.0.0.1 -P3306 -uroot -e"UPDATE mysql.user SET password = PASSWORD('yourpassword') WHERE user = 'root'"

#4楼

This should do the trick 这应该可以解决问题

export DEBIAN_FRONTEND=noninteractive
sudo -E apt-get -q -y install mysql-server

Of course, it leaves you with a blank root password - so you'll want to run something like 当然,它会留下一个空白的root密码 - 所以你想要运行类似的东西

mysqladmin -u root password mysecretpasswordgoeshere

Afterwards to add a password to the account. 然后为帐户添加密码。


#5楼

sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password your_password'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password your_password'
sudo apt-get -y install mysql-server

For specific versions, such as mysql-server-5.6 , you'll need to specify the version in like this: 对于特定版本,例如mysql-server-5.6 ,您需要像这样指定版本:

sudo debconf-set-selections <<< 'mysql-server-5.6 mysql-server/root_password password your_password'
sudo debconf-set-selections <<< 'mysql-server-5.6 mysql-server/root_password_again password your_password'
sudo apt-get -y install mysql-server-5.6

For mysql-community-server, the keys are slightly different: 对于mysql-community-server,密钥略有不同:

sudo debconf-set-selections <<< 'mysql-community-server mysql-community-server/root-pass password your_password'
sudo debconf-set-selections <<< 'mysql-community-server mysql-community-server/re-root-pass password your_password'
sudo apt-get -y install mysql-community-server

Replace your_password with the desired root password. 将your_password替换为所需的root密码。 (it seems your_password can also be left blank for a blank root password.) (对于空白的root密码,似乎your_password也可以留空。)

If your shell doesn't support here-strings ( zsh , ksh93 and bash support them), use: 如果你的shell不支持here-stringszshksh93bash支持它们),请使用:

echo ... | sudo debconf-set-selections

在没有密码提示的情况下在Ubuntu上安装MySQL相关推荐

  1. 安装mysql没有密码_如何在没有密码提示的情况下安装MySQL?

    问题描述 我试图在没有密码提示的情况下在Ubuntu Natty上安装MySQL.但是,在主安装后的某个阶段,我总是不断提示输入密码. 另外,当我输入我认为应该是我的密码(mymysqlpass)的密 ...

  2. web服务器显示禁用,win10系统打开ppt提示默认情况下禁用对此web服务器的访问的处理办法...

    有关win10系统打开ppt提示默认情况下禁用对此web服务器的访问的操作方法想必大家有所耳闻.但是能够对win10系统打开ppt提示默认情况下禁用对此web服务器的访问进行实际操作的人却不多.其实解 ...

  3. .net4.5对应的安装mysql dll文件的版本_cmd下使用mysql插入中文出现无法退出语句的情况!终极解决办法! 安装mysql详细教程。...

    当你插入中文时遇到这种情况,始终无法退出. 当前数据库:网上下载的奇奇怪怪版本5.5 当前系统win10 当前CMD输入编码utf8 数据库编码utf8 表编码utf8 mysql> inser ...

  4. 键盘上哪个键是插入建_如何在没有插入键的情况下按键盘上的“插入”?

    键盘上哪个键是插入建 Finding a keyboard that has all the features you want can be a bit of a task at times, bu ...

  5. Mac OS X 下 TAR.GZ 方式安装 MySQL

    Mac OS X 下 TAR.GZ 方式安装 MySQL 注意: 本篇文章适用与 MySQL 5.6 版本的安装, 但已不再适用 5.7 的安装, 5.7 的安装方式请参见:<Mac OS X ...

  6. centos lnmp源码安装mysql_CentOS 6.6 下源码编译安装MySQL 5.7.5

    说明:CentOS 6.6 下源码编译安装MySQL 5.7.5 1. 安装相关工具 # yum -y install gcc-c++ ncurses-devel cmake make perl \ ...

  7. linux软件安装非系统盘,linux操作系统可不可以像安装windows软件一样在windows系统下的硬盘上安装...

    linux操作系统可不可以像安装windows软件一样在windows系统下的硬盘上安装 答案:2  信息版本:手机版 解决时间 2020-07-24 14:13 已解决 2020-07-23 16: ...

  8. 使用yum命令安装mysql_Linux Centos 下使用yum 命令安装mysql实现步骤

    linux centos 下使用yum 命令安装mysql实现步骤 1. 查看服务器中有没有安装过mysql 1. 查看有没有安装包: yum list mysql* #移除已经安装的mysql yu ...

  9. CentOS 下使用yum 命令安装MySQL

    CentOS Linux下使用yum 命令安装MySQL过程记录. 1. 查看服务器中有没有安装过MySQL 1. 查看有没有安装包:     yum list mysql*     #移除已经安装的 ...

最新文章

  1. Nmap扫描参数解析(转)
  2. 有限元ansys/lsdyna学习笔记-01
  3. 《Python Cookbook 3rd》笔记(2.3):用Shell通配符匹配字符串
  4. 《Java8实战》笔记(08):重构、测试和调试
  5. __property 关键字的使用
  6. python中pop用法_python中pop()函数的用法
  7. android 快速请求取消,Android OkHttp + Retrofit 取消请求的方法
  8. 七牛云存储,资源云存储平台
  9. git+vue项目实战
  10. ubuntu安装vmplayer出现问题的解决方法
  11. java毕业设计总结
  12. free-mybatis-plugin插件下载
  13. HDU6438-Buy and Resell(贪心、思维题)
  14. apache kafka技术分享系列(目录索引)
  15. Prometheus为你的SpringBoot应用保驾护航
  16. C语言编程>第二十五周 ① 给定程序中,函数fun的功能是:在形参s所指字符串中的每个非数字字符之后插入一个“*”号。
  17. idea插件 之~~~~mybatisx(忍者鸟)、lombox(小辣椒)
  18. 原型设计工具 - Mockplus
  19. 从android 看微信小程序
  20. python爬取腾讯新闻_python爬虫实战――爬取腾讯新闻 !

热门文章

  1. EJB MEMCACHED 缓存技术
  2. Windows7快捷键大全
  3. python filter
  4. 校外实习报告(二十)
  5. 2016/05/13 thinkphp 3.2.2 ① 数据删除及执行原生sql语句 ②表单验证
  6. arcgis server缓存路径修改
  7. 嵌入式成长轨迹52 【Zigbee项目】【CC2430基础实验】【在PC用串口收数并发数】...
  8. 各j2ee web层框架比较(转)
  9. 【转载】Delphi获取与设置系统时间格式(长日期与短日期)
  10. Zabbix监控Nginx连接状态