张裕 发表于 2024-8-10 21:11:39

Ubuntu安装MySQL

题目

在Ubuntu安装MySQL时建议直接利用系统命令安装,假如利用官网下载安装包的方式非常复杂。
安装设置

1.安装

sudo apt-get update
我在安装的时间这一步都出现题目,见了鬼了,排查后是因为网络题目,无法访问清华镜像导致的题目,后来通过更换阿里云镜像解决(阿里云镜像有点 慢,他们说科大的比力快)。假如这一步正常运行就不消管了。
##########################################################################
ps:如何更换镜像源
1.备份原来的源,将以前的源备份一下,以防以后可以用的。
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak 2.打开/etc/apt/sources.list文件
sudo vim /etc/apt/sources.list 3.清空文件内容,更换为下面内容(第一行你不要删)
#添加阿里源
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
3.更新
sudo apt-get update
如出现依靠题目,解决方式如下:
sudo apt-get -f install ####################################################################
然后利用如下命令安装
sudo apt install mysql-server 完成后:
https://i-blog.csdnimg.cn/direct/0c670177689d41f3931b06dabeeee8cd.png
2.设置

1.查看MySQL状态
sudo systemctl status mysql https://i-blog.csdnimg.cn/direct/993e7105d50f4ea29180ed3e48ab29f7.png
2.设置暗码
安装后的初始用户暗码是随机的,需要查看一下再修改。
sudo cat /etc/mysql/debian.cnf https://i-blog.csdnimg.cn/direct/09625012785a47f18a74cf5b7991bb53.png
登录
mysql -u debian-sys-maint -p 随后输入暗码
https://i-blog.csdnimg.cn/direct/d71c33208ecb4e4093b6d72f3572fc9a.png
成功进入
更改暗码
use mysql;
select user,plugin from user; https://i-blog.csdnimg.cn/direct/048c9fb7d1644a189062b7cc407d4add.png
更改暗码设置
update user set plugin='mysql_native_password' where user ='root'; https://i-blog.csdnimg.cn/direct/4b0716909bee454c88f62758b1f8ff7f.png
刷新设置
flush privileges;
更改暗码
alter user 'root'@'localhost' identified by '1234'; https://i-blog.csdnimg.cn/direct/db48b99dda444ba79ca04406e42c74ea.png
这一步可能会报错,如下
https://i-blog.csdnimg.cn/direct/8478b0e16718424f8951298b1251d216.png
这时要改一下暗码策略
set global validate_password.policy = 0;
set global validate_password.length = 4; 降低暗码的校验规则之后,再次执行上述修改暗码的指令。
退出
https://i-blog.csdnimg.cn/direct/09e5525af29e4993ab9b4a15e8353ea2.png
重新登录
https://i-blog.csdnimg.cn/direct/14f86c11829a4ba5b64001464188ae9b.png
成功!
创建远程用户

默认的root用户只能当前节点localhost访问,是无法远程访问的,我们还需要创建一个root账户,用户远程访问
create user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '1234'; 分配权限
grant all on *.* to 'root'@'%'; 然后就可以利用root用户通过恣意ip远程毗连了。


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Ubuntu安装MySQL