linux安装mysql8.11_Ubuntu安装MySQL任意版本(18.04亲测)

本文详细介绍了如何在Ubuntu 18.04上安装MySQL,包括安装默认仓库的5.7版本和通过添加源选择安装8.0版本。步骤包括更新仓库、安装、设置密码、安全配置以及服务的启停和自启动管理。
摘要由CSDN通过智能技术生成

1. 前言

本文主要讲解如何在Ubuntu系统上安装各种版本的MySQL,根据个人需求可选择不同的版本,本文所有安装过程和效果都在是在Ubuntu Server 18.04上实现的。基于Ubuntu的其它Linux系统大同小异,同样可参考本教程。

2. 安装Ubuntu默认仓库版本

需要安装其他版本请直接跳过这步

更新apt仓库缓存:

zcwyou@ubuntu1804:~$ sudo apt update

更新apt仓库缓存

cea40e2259c96556975f7cd84927ca28.png

查询当前仓库的mysql版本

zcwyou@ubuntu1804:~$ sudo apt-cache show mysql-server

执行结果如下:

Package: mysql-server

Architecture: all

Version: 5.7.24-0ubuntu0.18.04.1

Priority: optional

Section: database

Source: mysql-5.7

Origin: Ubuntu

Maintainer: Ubuntu Developers ubuntu-devel-discuss@lists.ubuntu.com

Original-Maintainer: Debian MySQL Maintainers pkg-mysql-maint@lists.alioth.debian.org

可以看到Ubuntu18.04仓库里默认的MySQL版本为 5.7.24

安装当前仓库的mysql版本

zcwyou@ubuntu1804:~$ sudo apt install mysql-server -y

Reading package lists… Done

Building dependency tree

Reading state information… Done

The following additional packages will be installed:

libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-6 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl

libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libtimedate-perl liburi-perl

mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7

Suggested packages:

libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx tinyca

The following NEW packages will be installed:

libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-6 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl

libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libtimedate-perl liburi-perl

mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7 mysql-server-core-5.7

0 upgraded, 21 newly installed, 0 to remove and 1 not upgraded.

Need to get 21.0 MB of archives.

After this operation, 162 MB of additional disk space will be used.

可以看到,安装mysql 5.7占用空间为162MB。

到这里为止,mysql 5.7已经安装成功。

接下来就是安装后的配置

ubuntu安装mysql 5.7

7dbbc56d1135af5520832e5b5243bd07.png

设置数据库密码并加固安全策略:

zcwyou@ubuntu1804:~$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords

and improve security. It checks the strength of password

and allows the users to set only those passwords which are

secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y输入y验证密码插件

There are three levels of password validation policy:

LOW Length >= 8

MEDIUM Length >= 8, numeric, mixed case, and special characters

STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2选择2表示使用密码最强验证策略

Please set the password for root here.

New password: 设置mysql密码

Re-enter new password: 再次输入mysql密码

Estimated strength of the password: 50

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y输入y表示继续密码策略设置

By default, a MySQL installation has an anonymous user,

allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : y输入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? (Press y|Y for Yes, any other key for No) : y输入y禁止远程登录,根据实际需求定义

Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : y输入y删除test数据库

– 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? (Press y|Y for Yes, any other key for No) : y输入y重启数据库

Success.

All done!

设置mysql数据库

ac30871ceb56e1b59dbc487fdee5de70.png

查看mysql状态:

zcwyou@ubuntu1804:~$ sudo systemctl status mysql.service

下图中,看到active (running)表示正在运行,enabled表示开机自动启动

● mysql.service – MySQL Community Server

Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)

Active: active (running) since Tue 2019-01-08 01:32:27 UTC; 9min ago

查看mysql状态

44a5e454c183deaa5c57c611d61b23db.png

至此,Ubuntu默认版本已经安装启动完毕。

重启mysql服务

zcwyou@ubuntu1804:~$ sudo systemctl restart mysql.service

取消mysql服务自启动:

zcwyou@ubuntu1804:~$ sudo systemctl disable mysql.service

设置mysql服务自启动:

zcwyou@ubuntu1804:~$ sudo systemctl enable mysql.service

如果要删除刚刚安装的版本,执行以下命令:

zcwyou@ubuntu1804:~$ sudo apt remove mysql-server -y && sudo apt auto-remove -y

安装Ubuntu其他版本

浏览器打开以下链接:

https://dev.mysql.com/downloads/

打开mysql下载页面

c34252a13afd3053ea58f654892d2f38.png

点击下载mysql

6ffef6f052d44e8f11018a544f269df9.png

查看mysql下载地址

486430b299a57302837baf826c38ee7e.png

复制mysql下载地址

ca1bf160bff930a94ea8616ed00f55b2.png

使用wget下载mysql

zcwyou@ubuntu1804:~$ wget https://dev.mysql.com/get/mysql-apt-config_0.8.11-1_all.deb

使用wget下载mysql

3223b8ded40afff61e0864995ea49cdf.png

执行以下命令,添加mysql的源仓库并选择mysql版本,假设下载回来的文件名为mysql-apt-config_0.8.11-1_all.deb

如果以后重新选择,也是使用以下命令:

zcwyou@ubuntu1804:~$ sudo dpkg -i mysql-apt-config_0.8.11-1_all.deb

选择第一个选择配置mysql版本

9a24ed5cbbe68446d7ae268808bd77ff.png

根据需求选择mysql版本,这里选择8.0

9cb8950c77fc13d97c818f58a6f29cef.png

选择OK确认mysql的安装配置

809decc1d53fdba8f8932836a11e0973.png

更新仓库缓存:

zcwyou@ubuntu1804:~$ sudo apt update

确认版本。注意的是仓库默认的mysql名称为mysql-server,而刚刚添加的仓库里的mysql软件包名称为mysql-community-server,所以我们需要查询的是mysql-community-server版本

zcwyou@ubuntu1804:~$ sudo apt-cache show mysql-community-server

Package: mysql-community-server

Source: mysql-community

Version: 8.0.13-1ubuntu18.04

Architecture: amd64

Maintainer: MySQL Release Engineering mysql-build@oss.oracle.com

可以看到,mysql-community-server版本为8.0.13,这也是我们刚刚选择的版本。

安装它:

zcwyou@ubuntu1804:~$ sudo apt install -y mysql-community-server

图13:安装mysql-community-server

52e45549d09cb5a889866ef3da79b3a2.png

图14:设置mysql密码

1bd19936814106b8fc433af53a02a067.png

设置密码加密强度

6233e78bb7125493aa9cc64a0d8387c7.png

安装后的配置请参考上面的教程。

查看mysql状态:

zcwyou@ubuntu1804:~$ sudo systemctl status mysql.service

重启mysql服务

zcwyou@ubuntu1804:~$ sudo systemctl restart mysql.service

取消mysql服务自启动:

zcwyou@ubuntu1804:~$ sudo systemctl disable mysql.service

设置mysql服务自启动:

zcwyou@ubuntu1804:~$ sudo systemctl enable mysql.service

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值