当前位置: 首页 > news >正文

Ubuntu 22.04.3 LTS 安装 MySQL

  1. 更新系统包索引
sudo apt update
sudo apt upgrade -y
  1. 安装MySQL
sudo apt install mysql-server -y

检查MySQL服务状态

sudo systemctl status mysql

运行MySQL安全配置脚本

sudo mysql_secure_installation
设置root密码
删除匿名用户
容许root远程登录
删除测试数据库
重新加载权限表
sudo mysql_secure_installationSecuring the MySQL server deployment.Connecting to MySQL using a blank password.VALIDATE PASSWORD COMPONENT 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 component?Press y|Y for Yes, any other key for No:Skipping password set for root as authentication with auth_socket is used by default.
If you would like to use password authentication instead, this can be done with the "ALTER_USER" command.
See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information.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
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) :... skipping.
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- 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
Success.All done!

1. 设置root用户密码

登录到MySQL:

sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
FLUSH PRIVILEGES;

2. 允许root用户从任何主机连接

MySQL 8.0中,需要创建一个新的root用户条目,允许从任何主机连接:

CREATE USER 'root'@'%' IDENTIFIED BY '新密码';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

3. 配置MySQL监听所有网络接口

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
#bind-address		= 127.0.0.1
bind-address		= 0.0.0.0
#mysqlx-bind-address	= 127.0.0.1
mysqlx-bind-address	= 0.0.0.0

4. 重启MySQL服务

sudo systemctl restart mysql

5. 配置防火墙允许MySQL连接

sudo ufw allow mysql
sudo ufw allow 3306/tcp

6. 查询用户表以查看认证插件信息

mysql> SELECT user, host, plugin FROM mysql.user WHERE user='root';
+------+-----------+-----------------------+
| user | host      | plugin                |
+------+-----------+-----------------------+
| root | %         | caching_sha2_password |
| root | localhost | mysql_native_password |
+------+-----------+-----------------------+
2 rows in set (0.00 sec)

将远程root用户的认证插件更改为 mysql_native_password

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码';
FLUSH PRIVILEGES;
systemctl restart mysql

7. 测试远程连接

mysql -h 服务器IP地址 -P 3306 -u root -p

8. 修改MySQL端口

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
port = 3600

9. 重启MySQL服务以应用更改

sudo systemctl restart mysql

10. 验证MySQL是否在新端口上监听

sudo netstat -tlnp | grep mysql
sudo ss -tlnp | grep mysql
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)mysql>
http://www.dtcms.com/a/287592.html

相关文章:

  • 【数据结构初阶】--双向链表(二)
  • 基于单片机病床呼叫系统/床位呼叫系统
  • 【自用】JavaSE--集合框架(一)--斗地主案例
  • Baumer工业相机堡盟工业相机如何通过YoloV8深度学习模型实现动物分类(C#源码,UI界面版)
  • Python 常见库分类介绍及安装方法
  • 数据库第四次作业
  • 爬虫小知识三:selenium库
  • ElasticSearch:商品SKU+SPU实现join查询,设计及优化
  • 基于Eureka和restTemple的负载均衡
  • gitlab私有化部署
  • 月舟科技近调记录
  • Kotlin内联函数
  • 访问 gitlab 跳转 0.0.0.0
  • Kotlin泛型约束
  • QGIS新手教程10:专题图制作与图层渲染技巧全攻略(含分类与渐变)
  • 【通识】PCB文件
  • Elastic Search 8.x 分片和常见性能优化
  • IntelliJ IDEA中Mybatis的xml文件报错解决
  • 在Tailwind Css中如何书写flex布局
  • Linux C 信号操作
  • MCP 协议详细分析一 initialize ping tools/list tools/call
  • 13.5 Meta LLaMA 2核心技术拆解:4T数据训练+30%显存优化,70B模型准确率82.6%
  • Android Auto 即将推出新功能
  • LeetCode|Day19|14. 最长公共前缀|Python刷题笔记
  • Java无服务架构新范式:Spring Native与AWS Lambda冷启动深度优化
  • KVM中使用桥接模式.运维就业技术教程
  • NLP中情感分析与观念分析、价值判断、意图识别的区别与联系,以及四者在实际应用中的协同
  • 枚举类高级用法
  • 实验-链路聚合
  • Java多线程基础详解:从实现到线程安全