簡體   English   中英

Vagrant無法運行mysql 5.6安裝的Provision Shell腳本

[英]Provision shell script for mysql 5.6 install is not working in 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 ---

知道如何正確安裝MySQL 5.6版本嗎?

更新:我已經嘗試過(如答案中所建議)

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數據庫遷移到新服務器

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM