Ghost 默认采用 Sqlite3 数据库,但是我还是建议用 MySQL,避免将来由于数据多、访问量多而导致性能下降。
注意:本系列教程只是针对阿里云上的 Ubuntu 12.04 。本章讲解的 MySQL 安装、设置是针对 5.5 版本。如果你的版本不同,有可能会出现问题,建议谷歌一下解决方案。
开始安装 MySQL
执行如下指令开始安装 MySQL 吧:
sudo apt-get install mysql-server mysql-client
由于 MySQL 安装包较大,安装的时间会稍微长一些。安装过程中,系统会提示你给 root
用户(这里的 root 是 MySQL 数据库的管理账号) 设置个密码,建议设置的复杂些,更加安全些。如下图:
加强 MySQL 安全设置
MySQL 安装成功后,我们执行以下指令进一步加强 MySQL 的安全设置:
sudo mysql_secure_installation
此工具所做的增强安全设置包括:移除所有匿名账户、限制远程 root 账户登录、删除 test 数据库等。下面列出详细设置:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
//输入安装 MySQL 时为 root 账户设置的密码
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
You already have a root password set, so you can safely answer 'n'.
//是否修改 root 账户的密码?前面设置过 root 账户的密码了,如果不打算修改密码的话,输入 'n'
Change the root password? [Y/n] n
... skipping.
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
//是否删除匿名用户?
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
//是否禁止 root 账户远程登录?
Disallow root login remotely? [Y/n] y
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
//是否删除 MySQL 默认创建的 test 数据库,并删除所有对 test 数据库的权限设置?
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
//是否重新加载权限表?
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
OK!MySQL 到此就安装好了!
为 MySQL 设置默认字符集
将数据库、htnl页面、源码文件都设置为统一的字符集会减少很多麻烦,当然,utf8 是最好的选择。
打开 /etc/mysql/my.cnf
文件,为 [mysqld]
添加如下设置:
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
然后重启 MySQL。
为了确保设置成功,我们检查一下:
- 进入 MySQL 命令行界面:
mysql -uroot -p
- 输入指令:
show variables like 'char%';
,输出是否如下所示: - 再输入指令:
show variables like 'collation%';
检查一下结果:
如果是上面的结果,恭喜你,搞定 MySQL 了!!!