Ubuntu 16.04下如何安装MariaDB

引言: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:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imported: 1&nbsp; (RSA: 1)

sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] xenial main'

这里选中清华的数据服务

sudo apt update

执行结果如下:

linuxidc@linuxidc:~$ sudo apt update
Hit:1 xenial InRelease
Hit:2 xenial-updates InRelease                                       
Get:3 xenial-backports InRelease [92.2 kB]                           
Get:4 xenial-security InRelease [94.5 kB]         
Hit:5 xenial InRelease                         
Get:6 xenial InRelease [3,874 B]                                                       
Get:7 xenial/main amd64 Packages [5,865 B]                                             
Get:8 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 xenial/main amd64 galera-3 amd64 25.3.15-xenial [7,741 kB]
Get:2 xenial/main amd64 gawk amd64 1:4.1.3+dfsg-0.1 [398 kB]
Get:3 xenial/main amd64 iproute all 1:4.3.0-1ubuntu3 [2,428 B]                                                     
Get:4 xenial/universe amd64 libjemalloc1 amd64 3.6.0-9ubuntu1 [78.9 kB]                                           
Get:5 xenial/universe amd64 socat amd64 1.7.3.1-1 [321 kB]                                                         
Get:6 xenial/main amd64 mariadb-server all 10.2.1+maria-1~xenial [2,960 B]                       
Get:7 xenial/main amd64 libmysqlclient18 amd64 10.2.1+maria-1~xenial [2,932 B]                   
Get:8 xenial/main amd64 mariadb-common all 10.2.1+maria-1~xenial [3,234 B]                       
Get:9 xenial/main amd64 libmariadbclient18 amd64 10.2.1+maria-1~xenial [583 kB]                 
Get:10 xenial/main amd64 mariadb-client-core-10.2 amd64 10.2.1+maria-1~xenial [689 kB]           
Get:11 xenial/main amd64 mariadb-client-10.2 amd64 10.2.1+maria-1~xenial [1,095 kB]             
Get:12 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
#
deb [arch=amd64,i386] xenial main
deb-src xenial main

3. 无法连接Mariadb的问题

安装完成Mariadb之后,基于mysql workbench无法连接mariadb, 提示"Plugin 'unix_socket' is not loaded"的错误细心:

Ubuntu 16.04下如何安装MariaDB

什么是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

Ubuntu 16.04下如何安装MariaDB

杀掉进程,重新启动服务

 >> 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下如何安装MariaDB

然后就可以正常访问了。

Ubuntu 16.04 LTS 上安装 Nginx、MariaDB 和 HHVM 运行 WordPress 

Ubuntu 16.04 Dockerfile 安装MariaDB 

Linux系统教程:如何检查MariaDB服务端版本 

MariaDB Proxy读写分离的实现

Linux下编译安装配置MariaDB数据库的方法

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/219a652fb398caad5c6fbd70d51faccf.html