UbuntuServer22.04LTS在线安装MySQL8.x

UbuntuServer22.04LTS在线安装MySQL8.x

文章目录

  • UbuntuServer22.04LTS在线安装MySQL8.x
  • [1. 安装](#1. 安装)
    • [1. 官网](#1. 官网)
    • [2. 在线安装](#2. 在线安装)
    • [3. 修改密码及设置远程登录](#3. 修改密码及设置远程登录)
    • [4. 其他配置参考](#4. 其他配置参考)
  • [2. 启动和停止](#2. 启动和停止)
    • [1. 查看运行状态](#1. 查看运行状态)
    • [2. 开机自启](#2. 开机自启)
    • [3. 查看默认服务器配置命令](#3. 查看默认服务器配置命令)
  • [3. 登录](#3. 登录)

1. 安装

1. 官网

官网安装文档:MySQL :: MySQL 8.0 Reference Manual

官网APT在线安装文档:MySQL :: 使用 MySQL APT 存储库的快速指南

2. 在线安装

shell 复制代码
# 1.更新源
sudo apt update
# 2. 升级(可选)
sudo apt upgrade
# 3.安装MySQL服务
sudo apt install mysql-server

# 4. 看到下面信息则说明安装成功


done!
update-alternatives: using /var/lib/mecab/dic/ipadic-utf8 to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode
Setting up libhtml-parser-perl (3.72-5) ...#########################################################################################......................] 
Setting up libhttp-message-perl (6.22-1) ...###########################################################################################...................] 
Setting up mysql-server-8.0 (8.0.31-0ubuntu0.20.04.1) ...#################################################################################................] 
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode#########################################...............] 
Renaming removed key_buffer and myisam-recover options (if present)
mysqld will log errors to /var/log/mysql/error.log
mysqld is running as pid 1631
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
Setting up libcgi-pm-perl (4.46-1) ...#######################################################################################################.............] 
Setting up libhtml-template-perl (2.97-1) ...###################################################################################################..........] 
Setting up mysql-server (8.0.31-0ubuntu0.20.04.1) ...#############################################################################################........] 
Setting up libcgi-fast-perl (1:2.15-1) ...###########################################################################################################.....] 
Processing triggers for systemd (245.4-4ubuntu3.18) ...#################################################################################################..] 
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
root@jinshengyuan:/etc/mysql/conf.d# 

# 5. 查看安装版本
root@jinshengyuan:~# mysql -V
mysql  Ver 8.0.31-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

3. 修改密码及设置远程登录

安装完成后默认无密码

  1. 设置密码

这里以密码123456举例,最好设置为复杂的密码

shell 复制代码
# 1.先设置密码
mysql> alter user 'root'@'localhost' IDENTIFIED BY '123456';

mysql> flush privileges;
# 2.设置远程访问
msyql> alter user 'root'@'%' identified with mysql_native_password  by '123456';
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
  1. 设置远程访问
shell 复制代码
# 方式1:
mysql> GRANT ALL ON *.* TO 'root'@'%';

# 方式2:
mysql> use mysql
mysql> update user set host = '%' where user='root';
mysql> flush privileges;
  1. 查看认证插件
shell 复制代码
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | mysql_native_password |
| localhost | debian-sys-maint | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)

4. 其他配置参考

/etc/mysql/my.cnf

my.cnf配置文件内容如下

ini 复制代码
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
 
[mysqld]
# 设置3306端口
port = 3306
# 设置mysql的安装目录
# basedir=/home/lab_soft/mysql-8.0.31
# 设置 mysql数据库的数据的存放目录,MySQL 8+ 不需要以下配置,系统自己生成即可,否则有可能报错
# datadir=/home/lab_soft/mysql-8.0.31 #8.0以下版本需要配置数据目录
# 允许最大连接数
max_connections=5000
# 允许最大连接人数
max_user_connections=1000
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用"mysql_native_password"插件认证解决客户端无法连接的问题
default_authentication_plugin=mysql_native_password

2. 启动和停止

1. 查看运行状态

shell 复制代码
root@jinshengyuan:~# systemctl status mysql.service
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-11-03 09:22:43 CST; 6min ago
   Main PID: 1876 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 4423)
     Memory: 361.3M
     CGroup: /system.slice/mysql.service
             └─1876 /usr/sbin/mysqld

Nov 03 09:22:43 iZ2vcaf13jzrdbxaik2h6nZ systemd[1]: Starting MySQL Community Server...
Nov 03 09:22:43 iZ2vcaf13jzrdbxaik2h6nZ systemd[1]: Started MySQL Community Server.
root@jinshengyuan:~# 

2. 开机自启

MySQL服务器在安装后自动启动。 您可以使用 以下命令:

shell 复制代码
root@jinshengyuan:~# systemctl status mysql

3. 查看默认服务器配置命令

shell 复制代码
mysqld --verbose --help

3. 登录

shell 复制代码
sudo mysql

sudo mysql -u root
相关推荐
水饺编程12 分钟前
第2章:Linux 基础,切换用户
linux·c语言·汇编
Lsetea1 小时前
curl指定--tlsv1.2仍连接TLS1.3:最低版本与tls-max排查
linux·https·ssl证书·curl·tls
Lsetea1 小时前
curl访问HTTPS报47 Too many redirects:重定向循环与max-redirs排查
linux·http·https·ssl证书·curl
ha_lydms1 小时前
AnalyticDB MySQL 技术架构
大数据·hadoop·mysql·adb·spark·dataworks·1024程序员节
9624563 小时前
一次 Dell PowerEdge R750xs 启动故障复盘:从 iDRAC 带外管理到 Linux 多内核回退与 initramfs 重建
linux·运维·服务器
Zevalin爱灰灰3 小时前
Linux入门第一部分(Ubuntu入门篇) 第二章 浅尝Ubuntu(二)
linux·嵌入式·1024程序员节
Random Glow4 小时前
聚簇索引 vs 二级索引:回表、覆盖索引、索引下推
数据库·mysql·性能优化·innodb·1024程序员节·索引优化
北京中科新远科技4 小时前
高速接口兼容排查实战:OSFP、QSFP112与QSFP56如何逐层验证
linux·运维·网络
Ruiery4 小时前
Linux 6.6内核 CPU 深度解析(零):x86 内核引导协议 — 从 bootloader 到 main()
linux·运维·服务器
Ruiery4 小时前
Linux 6.6内核 CPU 深度解析(十六):x86 保护机制 — 从 ring 到页表的权限防线
linux·运维·服务器