共计 6454 个字符,预计需要花费 17 分钟才能阅读完成。
引言:MariaDB 在 MySQL 被 Oracle 收归旗下之后,开始作为 Linux 默认的数据库系统,这里主要描述在 Ubuntu 16.04 下如何来安装 MariaDB 的步骤。
1. 安装指令
sudo apt install software-properties-common
sudo apt-key adv –recv-keys –keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
执行结果:
Executing: /tmp/tmp.p9r0OfEIH2/gpg.1.sh –recv-keys
–keyserver
hkp://keyserver.ubuntu.com:80
0xF1656F24C74CD1D8
gpg: requesting key C74CD1D8 from hkp server keyserver.ubuntu.com
gpg: key C74CD1D8: public key “MariaDB Signing Key <signing-key@mariadb.org>” imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
sudo add-apt-repository ‘deb [arch=amd64,i386,ppc64el] http://mirrors.tuna.tsinghua.edu.cn/mariadb/repo/10.2/ubuntu xenial main’
这里选中清华的数据服务
sudo apt update
执行结果如下:
linuxidc@linuxidc:~$ sudo apt update
Hit:1 http://mirrors.aliyun.com/ubuntu xenial InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu xenial-updates InRelease
Get:3 http://mirrors.aliyun.com/ubuntu xenial-backports InRelease [92.2 kB]
Get:4 http://mirrors.aliyun.com/ubuntu xenial-security InRelease [94.5 kB]
Hit:5 http://archive.canonical.com/ubuntu xenial InRelease
Get:6 http://mirrors.tuna.tsinghua.edu.cn/mariadb/repo/10.2/ubuntu xenial InRelease [3,874 B]
Get:7 http://mirrors.tuna.tsinghua.edu.cn/mariadb/repo/10.2/ubuntu xenial/main amd64 Packages [5,865 B]
Get:8 http://mirrors.tuna.tsinghua.edu.cn/mariadb/repo/10.2/ubuntu xenial/main i386 Packages [5,864 B]
Fetched 202 kB in 7s (26.7 kB/s)
Reading package lists… Done
Building dependency tree
Reading state information… Done
3 packages can be upgraded. Run ‘apt list –upgradable’ to see them.
>> sudo apt install mariadb-server
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages were automatically installed and are no longer required:
linux-headers-4.4.0-28 linux-headers-4.4.0-28-generic linux-image-4.4.0-28-generic linux-image-extra-4.4.0-28-generic
Use ‘sudo apt autoremove’ to remove them.
The following additional packages will be installed:
galera-3 gawk iproute libjemalloc1 libmariadbclient18 libmysqlclient18 mariadb-client-10.2 mariadb-client-core-10.2 mariadb-common
mariadb-server-10.2 mariadb-server-core-10.2 socat
Suggested packages:
gawk-doc mailx mariadb-test tinyca
The following packages will be REMOVED:
mariadb-client-10.0 mariadb-client-core-10.0 mariadb-server-10.0 mariadb-server-core-10.0
The following NEW packages will be installed:
galera-3 gawk iproute libjemalloc1 libmariadbclient18 libmysqlclient18 mariadb-client-10.2 mariadb-client-core-10.2 mariadb-server-10.2
mariadb-server-core-10.2 socat
The following packages will be upgraded:
mariadb-common mariadb-server
2 upgraded, 11 newly installed, 4 to remove and 1 not upgraded.
Need to get 21.8 MB of archives.
After this operation, 48.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ftp.osuosl.org/pub/mariadb/repo/10.2/ubuntu xenial/main amd64 galera-3 amd64 25.3.15-xenial [7,741 kB]
Get:2 http://mirrors.aliyun.com/ubuntu xenial/main amd64 gawk amd64 1:4.1.3+dfsg-0.1 [398 kB]
Get:3 http://mirrors.aliyun.com/ubuntu xenial/main amd64 iproute all 1:4.3.0-1ubuntu3 [2,428 B]
Get:4 http://mirrors.aliyun.com/ubuntu xenial/universe amd64 libjemalloc1 amd64 3.6.0-9ubuntu1 [78.9 kB]
Get:5 http://mirrors.aliyun.com/ubuntu xenial/universe amd64 socat amd64 1.7.3.1-1 [321 kB]
Get:6 http://ftp.osuosl.org/pub/mariadb/repo/10.2/ubuntu xenial/main amd64 mariadb-server all 10.2.1+maria-1~xenial [2,960 B]
Get:7 http://ftp.osuosl.org/pub/mariadb/repo/10.2/ubuntu xenial/main amd64 libmysqlclient18 amd64 10.2.1+maria-1~xenial [2,932 B]
Get:8 http://ftp.osuosl.org/pub/mariadb/repo/10.2/ubuntu xenial/main amd64 mariadb-common all 10.2.1+maria-1~xenial [3,234 B]
Get:9 http://ftp.osuosl.org/pub/mariadb/repo/10.2/ubuntu xenial/main amd64 libmariadbclient18 amd64 10.2.1+maria-1~xenial [583 kB]
Get:10 http://ftp.osuosl.org/pub/mariadb/repo/10.2/ubuntu xenial/main amd64 mariadb-client-core-10.2 amd64 10.2.1+maria-1~xenial [689 kB]
Get:11 http://ftp.osuosl.org/pub/mariadb/repo/10.2/ubuntu xenial/main amd64 mariadb-client-10.2 amd64 10.2.1+maria-1~xenial [1,095 kB]
Get:12 http://ftp.osuosl.org/pub/mariadb/repo/10.2/ubuntu xenial/main amd64 mariadb-server-core-10.2 amd64 10.2.1+maria-1~xenial [4,456 kB]
2. 查看 sourcelist.
>> sudo vi /etc/apt/sources.list
# MariaDB 10.2 repository list – created 2016-08-14 12:39 UTC
# http://downloads.mariadb.org/mariadb/repositories/
deb [arch=amd64,i386] http://mirrors.tuna.tsinghua.edu.cn/mariadb/repo/10.2/ubuntu xenial main
deb-src http://mirrors.tuna.tsinghua.edu.cn/mariadb/repo/10.2/ubuntu xenial main
3. 无法连接 Mariadb 的问题
安装完成 Mariadb 之后,基于 mysql workbench 无法连接 mariadb, 提示 ”Plugin ‘unix_socket’ is not loaded” 的错误细心:
什么是 unix_socket plugin?
是一种安全机制,允许使用操作系统的安全机制连接数据库,通过 unix_socket 组件,通常使用用在 Ubuntu 15.04+ 以上的系统中。
解决的方法:
1. 尝试登陆 mysql 的命令, mysql -u root -p, 如果看到如下错误,则需要进入步骤2,否则直接进入步骤6.
linuxidc@linuxidc:~$ sudo mysql -u root -p
Enter password:
ERROR 1524 (HY000): Plugin ‘unix_socket’ is not loaded
这个原因是由于当前使用的 unix_socket 来进行连接,但是缺省的用户也无法进行访问。
2. 停止服务,使用设置 native 方式来访问,重置缺省密码
>> sudo systemctl stop mariadb # 停止服务
>> sudo mysqld_safe –skip-grant-tables & # 进入安全模式,并设置为后台进程
>> mysql -u root # 登陆 mysql
>> select Host,User,plugin from mysql.user where User=’root’; # 查询用户
>> update mysql.user set plugin=’mysql_native_password’; #重置加密模式
>> update mysql.user set password=PASSWORD(“newpassword”) where User=’root’; #重置密码
>> flush privileges; #刷新权限信息
>> exit
杀掉进程,重新启动服务
>> sudo kill -9 $(pgrep mysql) # 杀掉进程
>> sudo service mariadb start # 重新启动服务
3. 登陆 mysql, 安装 unix_soket
>> mysql -u root -p
>> install plugin unix_socket soname ‘auth_socket’;
然后就可以正常访问了。
Ubuntu 16.04 LTS 上安装 Nginx、MariaDB 和 HHVM 运行 WordPress http://www.linuxidc.com/Linux/2016-10/136435.htm
Ubuntu 16.04 Dockerfile 安装 MariaDB http://www.linuxidc.com/Linux/2016-09/135260.htm
Linux 系统教程:如何检查 MariaDB 服务端版本 http://www.linuxidc.com/Linux/2015-08/122382.htm
MariaDB Proxy 读写分离的实现 http://www.linuxidc.com/Linux/2014-05/101306.htm
Linux 下编译安装配置 MariaDB 数据库的方法 http://www.linuxidc.com/Linux/2014-11/109049.htm
CentOS 系统使用 yum 安装 MariaDB 数据库 http://www.linuxidc.com/Linux/2014-11/109048.htm
安装 MariaDB 与 MySQL 并存 http://www.linuxidc.com/Linux/2014-11/109047.htm
Ubuntu 上如何将 MySQL 5.5 数据库迁移到 MariaDB 10 http://www.linuxidc.com/Linux/2014-11/109471.htm
[翻译]Ubuntu 14.04 (Trusty) Server 安装 MariaDB http://www.linuxidc.com/Linux/2014-12/110048htm
Ubuntu 14.04(Trusty) 安装 MariaDB 10 数据库 http://www.linuxidc.com/Linux/2016-11/136833.htm
MariaDB 的详细介绍 :请点这里
MariaDB 的下载地址 :请点这里
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-04/142915.htm