更新软件库:
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)
文章评论