Ubuntu 16.04 系统卸载MySQL安装MariaDB教程

Ubuntu 16.04 系统卸载MySQL安装MariaDB教程
Ubuntu 16.04 系统卸载MySQL安装MariaDB教程

第一步: 卸载 MySQL

要在Ubuntu系统卸载MySQL,执行如下命令:

sudo systemctl stop mysql.service
sudo apt-get remove mysql-server mysql-common libmysqlclient18

执行完成后,就已经从Ubuntu系统上移除了MySQL,接下来我们开始安装MariaDB。

第二步: 安装 MariaDB

执行如下的命令安装 MariaDB。

sudo apt-get install mariadb-server mariadb-client libmariadbclient18

这个命令将直接从Ubuntu的软件库中安装MariaDB的稳定版本。

在安装过程中,可能会看到以下消息,提示旧数据目录将被保存到新位置。接受并继续。

┌────────────────────┤ Configuring mariadb-server-10.1 ├──────
│ The old data directory will be saved at new location
│ A file named /var/lib/mysql/debian-*.flag exists on this system. The
│ number indicates a database binary format version that cannot
│ automatically be upgraded (or downgraded).
│ Therefore the previous data directory will be renamed to
│ /var/lib/mysql-* and a new data directory will be initialized at
│ /var/lib/mysql.
│ Please manually export/import your data (e.g. with mysqldump) if needed.
│                                  <Ok>
│
└────────────────────────────────────────────────────────

但是,如果想要安装最新版本的MariaDB,运行以下命令以将MariaDB库密钥添加到Ubuntu。

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8

然后,运行以下命令以将MariaDB 10.2版软件库添加到Ubuntu。

sudo sh -c "echo 'deb [arch=amd64,i386] https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu '$(lsb_release -cs)' main' > /etc/apt/sources.list.d/MariaDB-10.1.list"

运行以下命令,安装 MariaDB 10.2:

sudo apt-get update
sudo apt-get install mariadb-server mariadb-client

如果想安装MariaDB 10.3版本,可以通过如下方式添加。

sudo sh -c "echo 'deb [arch=amd64,i386] https://mirrors.evowise.com/mariadb/repo/10.3/ubuntu '$(lsb_release -cs)' main' > /etc/apt/sources.list.d/MariaDB-10.2.list"

然后运行以下命令,安装MariaDB 10.2版本:

sudo apt-get update
sudo apt-get install mariadb-server mariadb-client

安装完成后,我们可以使用如下几个命令管理 MariaDB。

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

然后,执行如下命令,为MariaDB的root用户设置密码:

sudo mysql_secure_installation

安装提示,回答以下问题:

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]:  Y
  • Reload privilege tables now? [Y/n]:  Y

设置完成。

接下来,可以通过如下命令,登录MariaDB的root用户:

sudo mysql -u root -p

作者:牛奇网,本站文章均为辛苦原创,在此严正声明,本站内容严禁采集转载,面斥不雅请好自为之,本文网址:https://www.niuqi360.com/linux/ubuntu-16-04-remove-mysql-install-mariadb/

(1)
牛奇网牛奇网
上一篇 2021年4月2日 上午11:39
下一篇 2021年4月3日 下午2:27

发表回复

登录后才能评论
很多新手不知道如何选择外贸独立站主机,这里推荐一款使用量最大,性价比最高的国外独立站主机Hostinger,立即获取优惠