为mysql5.6安装提供shell脚本在Vagrant中不起作用


Provision shell script for mysql 5.6 install is not working in Vagrant

以下是我现在在Vagrant中上升时使用的内容。它可以与mysql5.5一起使用,但如果我试图将其更改为5.6,就会出现错误,并且安装不正确。如何在Vagrant中从shell脚本安装mysql-server-5.6有什么建议吗?

这是我当前的MySQL 5.5:脚本

#! /usr/bin/env bash
# Variables
MYSERVERNAME=mywebsite.laravel
APPENV=local
DBHOST=localhost
DBNAME=dbname
DBUSER=dbuser
DBPASSWD=password
echo -e "'n--- Setting super user role... ---'n"
sudo su
echo -e "'n--- Mkay, installing now... ---'n"
echo -e "'n--- Updating packages list ---'n"
apt-get -qq update
echo -e "'n--- Install base packages ---'n"
apt-get -y install vim curl build-essential python-software-properties git > /dev/null 2>&1
echo -e "'n--- Add some repos to update our distro ---'n"
add-apt-repository ppa:ondrej/php5 > /dev/null 2>&1
add-apt-repository ppa:chris-lea/node.js > /dev/null 2>&1
echo -e "'n--- Updating packages list ---'n"
apt-get -qq update
echo -e "'n--- Install MySQL specific packages and settings ---'n"
echo "mysql-server mysql-server/root_password password $DBPASSWD" | debconf-set-selections
echo "mysql-server mysql-server/root_password_again password $DBPASSWD" | debconf-set-selections
echo "phpmyadmin phpmyadmin/dbconfig-install boolean true" | debconf-set-selections
echo "phpmyadmin phpmyadmin/app-password-confirm password $DBPASSWD" | debconf-set-selections
echo "phpmyadmin phpmyadmin/mysql/admin-pass password $DBPASSWD" | debconf-set-selections
echo "phpmyadmin phpmyadmin/mysql/app-pass password $DBPASSWD" | debconf-set-selections
echo "phpmyadmin phpmyadmin/reconfigure-webserver multiselect none" | debconf-set-selections
apt-get -y install mysql-server-5.5 phpmyadmin > /dev/null 2>&1
echo -e "'n--- Setting up our MySQL user and db ---'n"
mysql -uroot -p$DBPASSWD -e "CREATE DATABASE $DBNAME"
mysql -uroot -p$DBPASSWD -e "grant all privileges on $DBNAME.* to '$DBUSER'@'localhost' identified by '$DBPASSWD'"
echo -e "'n--- Installing PHP-specific packages ---'n"
apt-get -y install php5 apache2 libapache2-mod-php5 php5-curl php5-gd php5-mcrypt php5-mysql php-apc > /dev/null 2>&1
echo -e "'n--- Some additional packages for PHP module development and PhalconPHP compiling ---'n"
apt-get -y install php5-dev libpcre3-dev gcc make > /dev/null 2>&1
echo -e "'n--- Enabling mod-rewrite ---'n"
a2enmod rewrite > /dev/null 2>&1
echo -e "'n--- Allowing Apache override to all ---'n"
sed -i "s/AllowOverride None/AllowOverride All/g" /etc/apache2/apache2.conf
#echo -e "'n--- Setting document root to public directory ---'n"
#rm -rf /var/www
#ln -fs /vagrant/public /var/www
echo -e "'n--- We definitly need to see the PHP errors, turning them on ---'n"
sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php5/apache2/php.ini
sed -i "s/display_errors = .*/display_errors = On/" /etc/php5/apache2/php.ini
echo -e "'n--- Turn off disabled pcntl functions so we can use Boris ---'n"
sed -i "s/disable_functions = .*//" /etc/php5/cli/php.ini
echo -e "'n--- Configure Apache to use phpmyadmin ---'n"
echo -e "'n'nListen 81'n" >> /etc/apache2/ports.conf
cat > /etc/apache2/conf-available/phpmyadmin.conf << "EOF"
<VirtualHost *:81>
    ServerAdmin webmaster@localhost
    DocumentRoot /usr/share/phpmyadmin
    DirectoryIndex index.php
    ErrorLog ${APACHE_LOG_DIR}/phpmyadmin-error.log
    CustomLog ${APACHE_LOG_DIR}/phpmyadmin-access.log combined
</VirtualHost>
EOF
a2enconf phpmyadmin > /dev/null 2>&1
echo -e "'n--- Add environment variables to Apache ---'n"
cat > /etc/apache2/sites-enabled/000-default.conf <<EOF
<VirtualHost *:80>
    DocumentRoot /var/www
    ServerName $MYSERVERNAME
    ErrorLog '${APACHE_LOG_DIR}/error.log
    CustomLog '${APACHE_LOG_DIR}/access.log combined
    SetEnv APP_ENV $APPENV
    SetEnv DB_HOST $DBHOST
    SetEnv DB_NAME $DBNAME
    SetEnv DB_USER $DBUSER
    SetEnv DB_PASS $DBPASSWD
</VirtualHost>
EOF
echo -e "'n--- Restarting Apache ---'n"
service apache2 restart > /dev/null 2>&1
echo -e "'n--- Installing Composer for PHP package management ---'n"
curl --silent https://getcomposer.org/installer | php > /dev/null 2>&1
mv composer.phar /usr/local/bin/composer
echo -e "'n--- Installing NodeJS and NPM ---'n"
apt-get -y install nodejs > /dev/null 2>&1
curl --silent https://npmjs.org/install.sh | sh > /dev/null 2>&1
echo -e "'n--- Installing javascript components ---'n"
npm install -g gulp bower > /dev/null 2>&1
echo -e "'n--- Updating project components and pulling latest versions ---'n"
cd /vagrant
sudo -u vagrant -H sh -c "composer install" > /dev/null 2>&1
cd /vagrant/client
sudo -u vagrant -H sh -c "npm install" > /dev/null 2>&1
sudo -u vagrant -H sh -c "bower install -s" > /dev/null 2>&1
sudo -u vagrant -H sh -c "gulp" > /dev/null 2>&1
echo -e "'n--- Creating a symlink for future phpunit use ---'n"
ln -fs /vagrant/vendor/bin/phpunit /usr/local/bin/phpunit

如何使其适用于MySQL 5.6?

我试图改变:

apt-get -y install mysql-server-5.5 phpmyadmin > /dev/null 2>&1

至:

apt-get -y install mysql-server-5.6 phpmyadmin > /dev/null 2>&1

但我得到了这个错误:

--- Setting up our MySQL user and db ---
==> default: Warning: Using a password on the command line interface can be insecure.
==> default: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
==> default: Warning: Using a password on the command line interface can be insecure.
==> default: ERROR
==> default:  2002 (HY000)
==> default: : Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
==> default: --- Installing PHP-specific packages ---

知道如何正确安装5.6版本的MySQL吗?

更新:我试过(如答案所示)

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mysql-server-5.6

sudo apt-get update
sudo apt-get upgrade

一切顺利,但最后一部分导致了这种情况:

$ sudo apt-get install mysql-server-5.6
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  mysql-client-5.6 mysql-client-core-5.6 mysql-common-5.6
  mysql-server-core-5.6
Suggested packages:
  mailx tinyca
The following packages will be REMOVED:
  mysql-client-5.5 mysql-client-core-5.5 mysql-server-5.5
  mysql-server-core-5.5
The following NEW packages will be installed:
  mysql-client-5.6 mysql-client-core-5.6 mysql-common-5.6 mysql-server-5.6
  mysql-server-core-5.6
0 upgraded, 5 newly installed, 4 to remove and 4 not upgraded.
Need to get 19.9 MB of archives.
After this operation, 69.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu/ trusty-updates/universe mysql-client-core-5.6 amd64 5.6.30-0ubuntu0.14.04.1 [4138 kB]
Get:2 http://archive.ubuntu.com/ubuntu/ trusty-updates/universe mysql-client-5.6 amd64 5.6.30-0ubuntu0.14.04.1 [5564 kB]
Get:3 http://archive.ubuntu.com/ubuntu/ trusty-updates/universe mysql-server-core-5.6 amd64 5.6.30-0ubuntu0.14.04.1 [4620 kB]
Get:4 http://archive.ubuntu.com/ubuntu/ trusty-updates/universe mysql-server-5.6 amd64 5.6.30-0ubuntu0.14.04.1 [5611 kB]
Get:5 http://archive.ubuntu.com/ubuntu/ trusty-updates/universe mysql-common-5.6 all 5.6.30-0ubuntu0.14.04.1 [13.4 kB]
Fetched 19.9 MB in 33s (597 kB/s)                                              
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_MONETARY = "en_US.UTF-8",
    LC_ADDRESS = "en_US.UTF-8",
    LC_TELEPHONE = "en_US.UTF-8",
    LC_NAME = "en_US.UTF-8",
    LC_MEASUREMENT = "en_US.UTF-8",
    LC_IDENTIFICATION = "en_US.UTF-8",
    LC_NUMERIC = "en_US.UTF-8",
    LC_PAPER = "en_US.UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_ALL to default locale: No such file or directory
Preconfiguring packages ...
(Reading database ... 73547 files and directories currently installed.)
Removing mysql-server-5.5 (5.5.49-0ubuntu0.14.04.1) ...
locale: Cannot set LC_ALL to default locale: No such file or directory
mysql stop/waiting
locale: Cannot set LC_ALL to default locale: No such file or directory
Removing mysql-client-5.5 (5.5.49-0ubuntu0.14.04.1) ...
Removing mysql-client-core-5.5 (5.5.49-0ubuntu0.14.04.1) ...
Removing mysql-server-core-5.5 (5.5.49-0ubuntu0.14.04.1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Selecting previously unselected package mysql-client-core-5.6.
(Reading database ... 73327 files and directories currently installed.)
Preparing to unpack .../mysql-client-core-5.6_5.6.30-0ubuntu0.14.04.1_amd64.deb ...
Unpacking mysql-client-core-5.6 (5.6.30-0ubuntu0.14.04.1) ...
Selecting previously unselected package mysql-client-5.6.
Preparing to unpack .../mysql-client-5.6_5.6.30-0ubuntu0.14.04.1_amd64.deb ...
Unpacking mysql-client-5.6 (5.6.30-0ubuntu0.14.04.1) ...
Selecting previously unselected package mysql-server-core-5.6.
Preparing to unpack .../mysql-server-core-5.6_5.6.30-0ubuntu0.14.04.1_amd64.deb ...
Unpacking mysql-server-core-5.6 (5.6.30-0ubuntu0.14.04.1) ...
Selecting previously unselected package mysql-server-5.6.
Preparing to unpack .../mysql-server-5.6_5.6.30-0ubuntu0.14.04.1_amd64.deb ...
locale: Cannot set LC_ALL to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_ALL to default locale: No such file or directory
Unpacking mysql-server-5.6 (5.6.30-0ubuntu0.14.04.1) ...
Selecting previously unselected package mysql-common-5.6.
Preparing to unpack .../mysql-common-5.6_5.6.30-0ubuntu0.14.04.1_all.deb ...
Unpacking mysql-common-5.6 (5.6.30-0ubuntu0.14.04.1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for ureadahead (0.100.0-16) ...
Setting up mysql-client-core-5.6 (5.6.30-0ubuntu0.14.04.1) ...
Setting up mysql-client-5.6 (5.6.30-0ubuntu0.14.04.1) ...
Setting up mysql-server-core-5.6 (5.6.30-0ubuntu0.14.04.1) ...
Setting up mysql-server-5.6 (5.6.30-0ubuntu0.14.04.1) ...
Installing new version of config file /etc/logrotate.d/mysql-server ...
Installing new version of config file /etc/init.d/mysql ...
Installing new version of config file /etc/init/mysql.conf ...
locale: Cannot set LC_ALL to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_ALL to default locale: No such file or directory
start: Job failed to start
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error processing package mysql-server-5.6 (--configure):
 subprocess installed post-installation script returned error exit status 1
E: Sub-process /usr/bin/dpkg returned an error code (1)

并且我无法登录phpmyadmin,所以我必须流浪销毁并再次流浪并使用5.5;(

知道它为什么失败以及如何修复吗?

虽然MySql 5.5是Ubuntu 14.04的默认版本,但MySql 5.6在默认存储库中可用。它可以简单地安装使用:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mysql-server-5.6

如果MySql 5.5数据库中有现有数据,则应自动迁移。尽管在进行重大升级之前备份总是一个好主意。

首先备份现有数据库中的数据:

mysqldump --lock-all-tables -u root -p --all-databases > dump.sql

然后在安装新版本后,如果需要,可以通过运行进行恢复

mysql -u root -p < dump.sql

有关迁移MySql数据库的更多信息,请查看:

如何在Ubuntu 14.04 上将MySQL数据库迁移到新服务器