安装

如果是第一次安装,则需要验证安装源。否则会提示:
W: GPG签名验证错误: http://ppa.launchpad.net intrepid Release: 由于没有公钥,下列签名无法进行验证: NO_PUBKEY 5A9BF3BB9D1A0061

故在安装MariaDB前需做如下步骤:

apt-get install software-properties-common

apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db

add-apt-repository 'deb http://mirrors.hustunique.com/mariadb/repo/10.0/debian jessie main'

MariaDB镜像源选择地址,参考官网https://downloads.mariadb.org/mariadb/repositories/#mirror=neusoft 本教程所列的镜像源可能无法使用

或者利用WinSCP添加源:

# MariaDB 10.0 repository list - created 2015-10-06 05:28 UTC
# http://mariadb.org/mariadb/repositories/
deb http://mirrors.hustunique.com/mariadb/repo/10.0/debian jessie main
deb-src http://mirrors.hustunique.com/mariadb/repo/10.0/debian jessie main

然后apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 1bb943db即可

接着
apt-get update更新下源

apt-get install mariadb-server安装MariaDB

安装过程中输入数据库密码两次,接着就安装完成。

加强MariaDB安全设置

MariaDB安装成功后,我们执行以下指令进一步加强MariaDB的安全设置:
mysql_secure_installation

此工具所做的增强安全设置包括:移除所有匿名账户、限制远程 root 账户登录、删除 test 数据库等。下面列出详细设置:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MARIADB SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current password for the root user. 
If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank,  so you should just press enter here.

//输入安装 MariaDB 时为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 MariaDB 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 MariaDB installation has an anonymous user, allowing anyone to log into MariaDB 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, MariaDB 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.

//是否删除 MariaDB 默认创建的 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 MariaDB installation should now be secure.

Thanks for using MariaDB!

到此就安装好了!

为 MySQL 设置默认字符集

打开/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%'; 检查一下结果:

成功完成所有,恭喜你,搞定MariaDB了!