当前位置:   article > 正文

ubantu20.4.4安装MySQL8.30_ubuntu 20.04在线安装database

ubuntu 20.04在线安装database

环境

系统版本:ubantu 20.4.4
MySQL版本:8.30

卸载历史MySQL

app@app:/data/mysql$ dpkg --list |grep mysql
rc  mysql-community-client                5.7.25-1ubuntu18.10                   amd64        MySQL Client
rc  mysql-community-server                5.7.25-1ubuntu18.10                   amd64        MySQL Server
ii  mysql-community-source                5.7.25-1ubuntu18.10                   amd64        MySQL source
app@app:/data/mysql$ sudo apt-get remove mysql-community-client --purge
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  mysql-community-client*
0 upgraded, 0 newly installed, 1 to remove and 50 not upgraded.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 123864 files and directories currently installed.)
Purging configuration files for mysql-community-client (5.7.25-1ubuntu18.10) ...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
--purge 参数是卸载的同时把配置文件一并删除
  • 1

下载MySQL

1、sudo mkdir /data/mysql8.0 -p
2、cd /data/mysql8.0/
3、sudo wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-server_8.0.30-1ubuntu20.04_amd64.deb-bundle.tar
如果没有wgt,执行sodu api-get install wget 安装即可
  • 1
  • 2
  • 3
  • 4
注意:需要关注ubuntu的版本,我的系统为20.4.4,下载对应系统的版本
  • 1

解压tar包

tar xf mysql-server_8.0.30-1ubuntu20.04_amd64.deb-bundle.tar
	参数解释:xf 解压文件
  • 1
  • 2

在这里插入图片描述

安装MySQL

#### 删除test相关的包
app@app:/data/mysql8.30$ ls *test* -l
-rw-r--r-- 1 app app 255532636 Jul  7 05:33 mysql-community-test_8.0.30-1ubuntu20.04_amd64.deb
-rw-r--r-- 1 app app  13224520 Jul  7 05:33 mysql-community-test-debug_8.0.30-1ubuntu20.04_amd64.deb
-rw-r--r-- 1 app app     68272 Jul  7 05:33 mysql-testsuite_8.0.30-1ubuntu20.04_amd64.deb

rm -fr *test*

app@app:/data/mysql8.30$ ls *test* -l
ls: cannot access '*test*': No such file or directory

安装MySQL
sudo dpkg -i mysql-*.deb
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

在这里插入图片描述
输入密码并回车,确认密码继续回车
在这里插入图片描述
注意,此处回车为使用强度高的密码进行验证,下面一个选项为旧的密码验证,8.0版本为安全度较高的版本,所以此处继续回车等待安装完成即可。

验证

app@app:/data/mysql8.30$ dpkg --list |grep mysql
ii  mysql-client                          8.0.30-1ubuntu20.04                   amd64        MySQL Client meta package depending on latest version
ii  mysql-common                          8.0.30-1ubuntu20.04                   amd64        Common files shared between packages
ii  mysql-community-client                8.0.30-1ubuntu20.04                   amd64        MySQL Client
ii  mysql-community-client-core           8.0.30-1ubuntu20.04                   amd64        MySQL Client Core Binaries
ii  mysql-community-client-plugins        8.0.30-1ubuntu20.04                   amd64        MySQL Client plugin
ii  mysql-community-server                8.0.30-1ubuntu20.04                   amd64        MySQL Server
ii  mysql-community-server-core           8.0.30-1ubuntu20.04                   amd64        MySQL Server Core Binaires
ii  mysql-community-server-debug          8.0.30-1ubuntu20.04                   amd64        Debug binaries for MySQL Server
ii  mysql-server                          8.0.30-1ubuntu20.04                   amd64        MySQL Server meta package depending on latest version
app@app:/data/mysql8.30$ ps -ef |grep mysql
mysql     625955       1  1 09:48 ?        00:00:01 /usr/sbin/mysqld
app       626319  621358  0 09:50 pts/0    00:00:00 grep --color=auto mysql
app@app:/data/mysql8.30$ systemctl status mysql
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-07-28 09:48:56 CST; 2min 14s ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
   Main PID: 625955 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 9443)
     Memory: 360.4M
     CGroup: /system.slice/mysql.service
             └─625955 /usr/sbin/mysqld

Jul 28 09:48:54 app systemd[1]: Starting MySQL Community Server...
Jul 28 09:48:56 app systemd[1]: Started MySQL Community Server.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

至此MySQL已经安装完成,但是还需要调试优化。

优化

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
追加到末尾
# 修改标签长度,默认1024
group_concat_max_len = 10240
# 最大睡眠时间
wait_timeout=300
# 超时时间设置
interactive_timeout = 500
# 允许最大的上传大小,默认1M
max_allowed_packet = 64M
# 指定字符编码
character_set_server=utf8mb4
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

配置密码复杂度

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
追加到末尾
plugin-load=validate_password.so
validate_password_policy=0
validate-password=FORCE_PLUS_PERMANENT
###重启MySQL 
sudo systemctl restart mysql
###登录mysql查看密码复杂度
app@app:~$ mysql -uroot -p123.com
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.30 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show variables like 'validate%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password_check_user_name    | ON    |
| validate_password_dictionary_file    |       |
| validate_password_length             | 8     |
| validate_password_mixed_case_count   | 1     |
| validate_password_number_count       | 1     |
| validate_password_policy             | LOW   |
| validate_password_special_char_count | 1     |
+--------------------------------------+-------+
7 rows in set (0.01 sec)
validate_password_check_user_name : 默认关闭,设置为ON时可以将密码设置成当前用户名
validate_password_dictionary_file : 检查密码的字典文件的路径名
validate_password_length : 默认为8,限制密码长度的最小字符数
validate_password_mixed_case_count : 默认值为1,限制小写字符和大写字符个数
validate_password_number_count : 默认值为1,限制数字的个数
validate_password_policy : 默认值为1, 密码强度等级 [LOW:0| MEDIUM:1 | STRONG:2]
validate_password_special_char_count : 默认值为1,限制特殊字符个数
validate_password_policy
0/LOW:只检查长度。
1/MEDIUM:检查长度、数字、大小写、特殊字符。
2/STRONG:检查长度、数字、大小写、特殊字符字典文件

###配置密码复杂度
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like 'validate%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password_check_user_name    | ON    |
| validate_password_dictionary_file    |       |
| validate_password_length             | 8     |
| validate_password_mixed_case_count   | 1     |
| validate_password_number_count       | 1     |
| validate_password_policy             | LOW   |
| validate_password_special_char_count | 1     |
+--------------------------------------+-------+
7 rows in set (0.00 sec)

###修改密码
mysql> alter user 'root'@'localhost' identified with mysql_native_password by '11111111';
Query OK, 0 rows affected (0.03 sec)
###授权远程登录
mysql> select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)
mysql> use mysql
mysql> update user set host='%'  where user='root';
Query OK, 1 row affected (0.03 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/65224?site
推荐阅读
相关标签
  

闽ICP备14008679号