Ubuntu下安装mysql步骤及常见问题
Ubuntu版本:20.04.1
- 更新数据源
apt-get update
- 安装mysql
apt-get install mysql
等待安装完成
- 设置root用户密码
安装完成后第一次进去无需密码,直接回车
mysql -uroot -p
登录成功后,选择mysql数据库
use mysql
先将authentication_string置空
update user set authentication_string=’’ where user=‘root’;
再设置密码
alter user ‘root’@‘localhost’ identified by ‘newpassword’;
最后刷新
flush privileges;
退出,使用新密码登录就好了
- 如果忘记了root密码
进入/etc/mysql/mysql.cnf.d文件夹
cd /etc/mysql/mysql.cnf.d
打开mysqld.cnf配置文件
vim mysqld.cnf
在[mysqld]下添加配置
skip-grant-tables
重启mysql服务
systemctl restart mysql;
最后重复步骤三
步骤三完成后去掉配置文件中的skip-grant-tables
- 远程连接设置
打开配置文件,注释bind-address,重启mysql服务
systemctl