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
相关推荐
泓度科技4 分钟前
单表百万数据查询慢 规范索引设计实现毫秒级响应
mysql·性能调优·数据库优化·索引设计·中小实体系统
开开心心就好2 小时前
定时结束进程的小工具,到点还能关机
linux·运维·服务器·智能手机·pdf·电脑·word
风翼靓崽2 小时前
ansible
linux·运维·ansible
遨游DATA2 小时前
容器退出码 126 排查:静态资源镜像层如何改写目录权限
linux·docker·kubernetes·文件权限
笔记本note2 小时前
Linux 定时器与时间管理
linux·时间·定时器
NPE~3 小时前
.sock 文件入门:从“文件路标”到进程间通信
linux·macos·教程·基础知识·.sock
做嵌入式网络的老骆3 小时前
01|VSS 400MB 就是内存泄漏吗?搞懂 Linux VSS、RSS、PSS 进程内存
linux
cpolar技术支持4 小时前
rsync -a 漏同步,-c 被 --update 吃掉
linux·备份·rsync·cpolar·数据校验
zxcvb1534 小时前
补上那个缺口:一个中小项目mysql做增量备份的完整思路
数据库·mysql·增量备份
女神下凡5 小时前
芯易选(152):炬芯(Actions)_开发指南
linux·arm开发·stm32·单片机·嵌入式硬件