如何在 Raspberry Pi 上成功安装 MySQL

发布网友

我来回答

3个回答

懂视网

Apache

Raspberry PI origins from UK. It is a small (credit-card size) fully functional PC that installs Linux. To now, there are two models A and B of Raspberry PI. The A model has 1 USB, 256MB RAM and The enhanced B model has 2 USB, 512 RAM. Both are equipped with ARM 700MHz (single core) CPU, a SD card slot. The B model also comes with an onboard Ethernet interface. The Raspberry PI requires a micro USB power (5V, 1A) and it doesn’t have the power switch. It can be connected to monitor using HDMI or TV using composite video (RCA).

Apache Server (PHP + MySQL) on Raspberry PI

The SD card is used as the booting device ‘hard drive’, a minimal 4GB is required. You can download Linux images fromofficial website. And you can use Win32 Disk Imager to write the *.img to SD card.

Win32 Disk Imager for Raspberry PI

Insert the SD card into Raspberry PI.

Insert the SD card into Raspberry PI.

Power it on and on the first time a configuration program (sudo raspi-config) will run. Using this configuration tool, you’ll be able to set up SSH, keyboard, Memory Split between CPU and GPU etc.

sudo raspi-config Raspberry PI.

SSH Raspberry PI.

Run the following command to install Apache2 and PHP,

sudo apt-get install apache2 php5 libapache2-mod-php5
sudo apt-get install apache2 php5 libapache2-mod-php5

And as we know, PHP without MySQL database is pretty much useless, so we use the following command to install MySQL.

sudo apt-get install mysql-server mysql-client php5-mysql
sudo apt-get install mysql-server mysql-client php5-mysql

During the MySQL setup, you will be prompted for the root password for MySQL database, and after that we’ll be able to check if MySQL is properly installed.

MySQL on Raspberry PI.

You can runsudo service mysql restartandsudo service apache restartto restart the MySQL and apache server manually. And you can runphp -vto see the version of PHP.

pi@raspberrypi:~$ php -vPHP 5.4.4-14+deb7u9 (cli) (built: Apr 26 2014 21:57:41) Copyright (c) 1997-2012 The PHP GroupZend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
pi@raspberrypi:~$ php -vPHP 5.4.4-14+deb7u9 (cli) (built: Apr 26 2014 21:57:41) Copyright (c) 1997-2012 The PHP GroupZend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

The apache server will store aindex.htmlby default on/var/www/index.htmland if you open a browser and type in the IP address of the Raspberry PI, you will get something like this, which means your Raspberry PI now serves as a HTTP server.

Apache Server on Raspberry PI.

–EOF–

GD Star Rating
loading...

GD Star Rating
loading...

热心网友

  首先你需要把官方的Raspbian镜像文件安装到SD卡上,然后启动Raspberry Pi。

  然而如果你试图用"sudo apt-get install mysql-server-5.5" 来安装MySQL的话将会失败。这是因为此操作会使SD卡上的文件系统全部占满。通过运行"df -h"命令可以查看此问题。
  

  SD大概有4GB的空间。文件 系统(可理解为官方的Raspbian镜像)大约有1.9GB。这个 文件系统是刚好适合2GB的卡(官方的Raspbian镜像是从2GB的卡上导出的,将该镜像写入的SD后,只占用SD卡2GB的空间,多余的空间需要手动扩展)。 调整文件系统以适合4GB的卡,你需要运行"sudo raspi-config" 并选择"expand_rootfs"选项。然后重启。

  现在运行命令“df -h”,系统会告诉你,你的文件系统还有足够的可用空间。
  但你的 MySQL 安装却失败了。因此你运行命令“sudo apt-get purge mysql-server-5.5”,并删除掉那些 mysql-server-5.5 的文件包和所有的相关文件。
  

  这时,如果你想用命令“ sudo apt-get install mysql-server-5.5”重新安装 MySQL,那将会再次失败。这是因为目录 /var/lib/mysql 里的数据文件是安装失败产生的数据文件。你应该先用命令“rm -rf /var/lib/mysql” 删除掉那些数据文件后,再用“sudo apt-get install mysql-server-5.5”命令进行安装。

  现在,你应该安装好了一个基本的MySQL。你可以执行命令“mysql_secure_installation” 来加强你的 MySQL 的安全性。

热心网友

首先你需要把官方的Raspbian镜像文件安装到SD卡上,然后启动Raspberry Pi。

然而如果你试图用"sudo apt-get install mysql-server-5.5" 来安装MySQL的话将会失败。这是因为此操作会使SD卡上的文件系统全部占满。通过运行"df -h"命令可以查看此问题。

SD大概有4GB的空间。文件 系统(可理解为官方的Raspbian镜像)大约有1.9GB。这个 文件系统是刚好适合2GB的卡(官方的Raspbian镜像是从2GB的卡上导出的,将该镜像写入的SD后,只占用SD卡2GB的空间,多余的空间需要手动扩展)。 调整文件系统以适合4GB的卡,你需要运行"sudo raspi-config" 并选择"expand_rootfs"选项。然后重启。

现在运行命令“df -h”,系统会告诉你,你的文件系统还有足够的可用空间。
但你的 MySQL 安装却失败了。因此你运行命令“sudo apt-get purge mysql-server-5.5”,并删除掉那些 mysql-server-5.5 的文件包和所有的相关文件。

这时,如果你想用命令“ sudo apt-get install mysql-server-5.5”重新安装 MySQL,那将会再次失败。这是因为目录 /var/lib/mysql 里的数据文件是安装失败产生的数据文件。你应该先用命令“rm -rf /var/lib/mysql” 删除掉那些数据文件后,再用“sudo apt-get install mysql-server-5.5”命令进行安装。

现在,你应该安装好了一个基本的MySQL。你可以执行命令“mysql_secure_installation” 来加强你的 MySQL 的安全性。

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com