红茶的个人站点

  • 首页
  • 专栏
  • 开发工具
  • 其它
  • 隐私政策
Awalon
Talk is cheap,show me the code.
  1. 首页
  2. 开发工具
  3. 正文

Ubuntu 安装 MySQL

2025年8月8日 11点热度 0人点赞 0条评论

更新软件库:

sudo apt update

安装:

sudo apt install mysql-server

启动服务:

sudo systemctl start mysql
sudo systemctl enable mysql

安全初始化配置:

sudo mysql_secure_installation
# 是否安装密码校验组件
Press y|Y for Yes, any other key for No: y 
# 密码强度设置
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 
#是否移除匿名帐号
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y 
# 是否阻止异地使用 root 帐号登录
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y 
# 是否移除测试库
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y 
# 是否立即重新加载规则表
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

Ubuntu 下默认安装的 MySQL 的 root 帐号是空密码,直接使用 sudo mysql 命令就可以连接:

sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.42-0ubuntu0.24.04.2 (Ubuntu)

连接后应当立即修改 root 帐号的密码:

mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'Mysql@123';

为了方便异地访问,还可以常见一个异地访问使用的帐号:

mysql> create user 'icexmoon'@'%' identified by 'Mysql@123';
Query OK, 0 rows affected (0.02 sec)
​
mysql> grant all on *.* to 'icexmoon'@'%';
Query OK, 0 rows affected (0.02 sec)

参考资料

  • MySQL 从入门到精通 1:SQL - 红茶的个人站点

本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: Linux MySQL ubuntu
最后更新:2025年8月8日

魔芋红茶

加一点PHP,加一点Go,加一点Python......

点赞
< 上一篇

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2021 icexmoon.cn. ALL RIGHTS RESERVED.
本网站由提供CDN加速/云存储服务

Theme Kratos Made By Seaton Jiang

宁ICP备2021001508号

宁公网安备64040202000141号