参考:cubuntu安装mysql5.6_mob649e81553a70的技术博客_51CTO博客
问题1:sudo apt install mysql-server-5.7 -y 若提示mysql-server 没有可安装候选
答:
sudo nano /etc/apt/sources.list
在开头加入:
# 阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
更新后即可安装:
sudo apt-get update
问题2:安装完成后,mysql -u root -p命令提示Access denied for user 'root'@'localhost'
root没有设置初始密码,先强行进入mysql再修改表设置密码
sudo mysql
mysql5.7
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';
FLUSH PRIVILEGES;
mysql 8
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'new_password';
FLUSH PRIVILEGES;
问题3:如何设置mysql的开机启动
sudo systemctl enable mysql