安装 mysql 数据库服务
安装mysql前,#1的vps需要先关闭apache2,因为mysql的安装会初始化数据,占了很大内存,如果apache2不关闭,有可能导致安装mysql失败。
1 输入如下命令关闭 apache2
/etc/init.d/apache2 stop
如果输入正确,会提示如下信息,表示apache2已经停止
root@241541:~# /etc/init.d/apache2 stop
* Stopping web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 0.3.175.133 for ServerName
... waiting [ OK ]
2 输入如下命令安装mysql
apt-get install mysql-server
如果输入正确,会提示如下信息,
root@241541:~# apt-get install mysql-server
Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient16
libnet-daemon-perl libplrpc-perl mysql-client-5.1 mysql-client-core-5.1
mysql-common mysql-server-5.1 mysql-server-core-5.1
Suggested packages:
libipc-sharedcache-perl libterm-readkey-perl tinyca
The following NEW packages will be installed:
libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient16
libnet-daemon-perl libplrpc-perl mysql-client-5.1 mysql-client-core-5.1
mysql-common mysql-server mysql-server-5.1 mysql-server-core-5.1
0 upgraded, 12 newly installed, 0 to remove and 26 not upgraded.
Need to get 22.9MB of archives.
After this operation, 54.4MB of additional disk space will be used.
Do you want to continue [Y/n]?
输入 Y 回车,继续安装 会提示输入 mysql 的 root 用户密码,你可以输入密码后回车,也可以不输入任何密码直接回车。 (不输入密码不会影响到Mysql的安全性,因为Mysql仅仅用于本地监听,但不输入密码会导致后续phpmyadmin无法运行)
需要重新输入一遍密码,如下图所示:
最后提示如下界面,表示mysql安装成功。
mysql 数据库优化
如果你的VPS的内存只有512M,请按如下步骤进行优化,如果是1G或以上可以忽略本步骤。执行本步骤可以将Mysql的占用内存由150M降到100M。
输入如下命令配置 Mysql
cp /etc/mysql/my.cnf /etc/mysql/my.cnf.`date +%s`
find /usr/share/doc/mysql* -name my-small.cnf -exec cp {} /etc/mysql/my.cnf \;
sed -i 's/skip-locking/user = mysql\n&/' /etc/mysql/my.cnf
执行结果如下所示:
root@241541:~# cp /etc/mysql/my.cnf /etc/mysql/my.cnf.`date +%s`
root@241541:~# find /usr/share/doc/mysql* -name my-small.cnf -exec cp {} /etc/mysql/my.cnf \;
root@241541:~# sed -i 's/skip-locking/user = mysql\n&/' /etc/mysql/my.cnf
重启下 Mysql服务:
/etc/init.d/mysql restart
执行结果如下所示:
root@241541:~# /etc/init.d/mysql restart
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql restart
Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the restart(8) utility, e.g. restart mysql
mysql start/running, process 9886