mysql 5.6安装的配置shell脚本在Vagrant中不起作用

时间:2016-05-10 11:37:53

标签: php mysql shell vagrant

这是我在Vagrant上升时使用的内容。它适用于mysql 5.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;(

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

1 个答案:

答案 0 :(得分:1)

虽然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数据库的更多信息,请查看:

How To Migrate a MySQL Database To A New Server On Ubuntu 14.04