ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

UBUNTU 16.04 LTS SERVER 手动升级 MariaDB 到最新版 10.2

2021-07-04 04:00:26  阅读:183  来源: 互联网

标签:LTS ... password MariaDB 16.04 sudo mysql 最新版 root


UBUNTU 16.04 LTS SERVER 手动升级 MariaDB 到最新版 10.2

1. 起因

最近因为不同软件的数据问题本来只是一些小事弄着弄着就越弄越麻烦了,期间有这么个需求,没看到有中文资源,特记录一文。

2. 升级

2.1 手动添加源并安装

切记!在做任何改动前务必先用 mysqldump 将所有数据先备份出来!!!血的教训啊。。通宵了我两晚才将数据恢复回去

首先,确认你机子上有装 software-properties-common:

sudo apt-get install software-properties-common

接着添加 MariaDB 的仓库公钥到包管理中:

sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8

然后添加 MariaDB 10.1 的源:

sudo sh -c \"echo \'deb https://mirrors.evowise.com/mariadb/repo/10.1/ubuntu \'$(lsb_release -cs)\' main\' > /etc/apt/sources.list.d/MariaDB101.list\"

这里最好是一步一步升级,所以先装 10.1 接着再升 10.2. 升级:

# 更新
sudo apt-get update

# 升级
sudo apt-get install mariadb-server mariadb-client

然后添加 MariaDB 10.2 的源:

sudo sh -c \"echo \'deb https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu \'$(lsb_release -cs)\' main\' > /etc/apt/sources.list.d/MariaDB102.list\"

升级:

# 更新
sudo apt-get update
# 升级
sudo apt-get install mariadb-server mariadb-client

到这里就手动升级完了,接着就是用 mysqldump 把数据还原回去了。

2.2 \"unix_socket\" 的错误解决办法

如果你从低版本升级到高版本或者从 MySQL 升到 MariaDB 都可能会遇到,比如刚装好的数据库不能登陆 root 账户了:

mysql \"ERROR 1524 (HY000): Plugin \'unix_socket\' is not loaded\"

这是因为这个叫 “unix_socket” 的东西是 MySQL 的一个认证的进程,但是在新的版本中它移除掉了!所以你的登陆就不能正常地认证了。。

解决办法如下:

先切成超管:

sudo su

接着彻底停掉 MySQL 并绕过验证地连上去:

/etc/init.d/mysql stop
mysqld_safe --skip-grant-tables &
mysql -uroot

完了下面的几句在 SQL Shell 中运行:

# 用 mysql 库
use mysql;

# 重置密码
update user set password=PASSWORD(\"mynewpassword\") where User=\'root\';

# 重设验证方式,去掉 unix_socket 恢复成正常的认证方式
update user set plugin=\"mysql_native_password\";

# 退出 SQL Shell
quit;

重启 MySQL:

/etc/init.d/mysql stop
kill -9 $(pgrep mysql)
/etc/init.d/mysql start

接着应该就能正常登陆了:

mysql -uroot -p

2.3 MariaDB 安全

下面这个命令可以自动设置一些数据库安全的东西,选做:

mysql_secure_installation

这个命令运行后会设置新的 root 密码,去除匿名用户,取消远程 root 的登陆并删除 test 库。

下面是运行的输出:

root@aliyun:/www# mysql_secure_installation

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.

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\'.

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.

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.

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 -V
mysql  Ver 15.1 Distrib 10.2.14-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

参考:

INSTALL / UPGRADE TO MARIADB 10.1 / 10.2 / 10.3 LATEST ON UBUNTU 16.04 LTS SERVER

Ubuntu 15.10 mysql error 1524 - unix_socket

完。

标签:LTS,...,password,MariaDB,16.04,sudo,mysql,最新版,root
来源: https://www.cnblogs.com/pycoco/p/14968157.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有