失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > linux安装mysql8.11_Ubuntu安装MySQL任意版本(18.04亲测)

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

时间:2019-03-27 00:44:18

相关推荐

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

1. 前言

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

2. 安装Ubuntu默认仓库版本

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

更新apt仓库缓存:

zcwyou@ubuntu1804:~$ sudo apt update

更新apt仓库缓存

查询当前仓库的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@

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

可以看到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

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

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数据库

查看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 -01-08 01:32:27 UTC; 9min ago

查看mysql状态

至此,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其他版本

浏览器打开以下链接:

/downloads/

打开mysql下载页面

点击下载mysql

查看mysql下载地址

复制mysql下载地址

使用wget下载mysql

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

使用wget下载mysql

执行以下命令,添加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版本

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

选择OK确认mysql的安装配置

更新仓库缓存:

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@

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

安装它:

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

图13:安装mysql-community-server

图14:设置mysql密码

设置密码加密强度

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

查看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

如果觉得《linux安装mysql8.11_Ubuntu安装MySQL任意版本(18.04亲测)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。