Linux下安装Mysql

Ubuntu下安装Mysql

1.安装MySQL Server

​ 安装命令:sudo apt install mysql-server

2.登录到mysql

​ 2.1查看默认的密码:sudo cat /etc/mysql/debian.cnf

​ 2.2使用debian账户登录进mysql

​ 2.3修改root密码(mysql8.0)

sh 复制代码
	use mysql; 
	update user set authentication_string='' where user='root';
	alter user 'root'@'localhost' identified with mysql_native_password by '123456';   

3.设置ubuntu固定IP

​ 3.1查看IP:ip a

4.开启ubuntu的SSH服务

​ 4.1执行下句,下载SSH服务

​ sudo apt-get install openssh-server

​ 4.2执行下句,验证下载后是否已经开启了服务:

​ ps -e | grep ssh

​ 4.3如果只有ssh-agent表示还没启动,执行下句,开启服务

​ /etc/init.d/ssh start

5.设置远程访问mysql

​ 5.1修改mysqld.cnf文件

​ 5.1.1设置修改权限

shell 复制代码
进入目录
/etc/mysql/mysql.conf.d
在mysqld.cnf所在文件目录下,通过修改
sudo chmod 777 mysqld.cnf
完成之后,可以按自己需求修改mysqld.cnf配置文件,但注意,修改完成后需要通过
sudo chmod 644 mysqld.cnf
将权限修改回来,否则配置文件并不会生效

6.修改root的host权限

shell 复制代码
连接数据库,这里以默认用户名密码为例
mysql -uroot -proot
show databases;
use mysql ;
select user,host from user;//可以看到user为root,host为localhost的话,说明mysql只允许本机连接,那么外网,本地软件客户端就无法连接了。
update user set host = '%' where user='root';
flush privileges;//刷新权限
相关推荐
乱蜂朝王1 小时前
Ubuntu 20.04安装CUDA 11.8
linux·运维·ubuntu
梁洪飞2 小时前
clk学习
linux·arm开发·嵌入式硬件·arm
老师我太想进步了20262 小时前
cmd连接MySQL及相关查询
数据库·mysql
~光~~2 小时前
【嵌入式linux驱动——点亮led】基于鲁班猫4 rk3588s
linux·点灯·嵌入式linux驱动
yuanmenghao3 小时前
车载Linux 系统问题定位方法论与实战系列 - 车载 Linux 平台问题定位规范
linux·运维·服务器·网络·c++
qq_589568104 小时前
centos6.8镜像源yum install不成功,无法通过镜像源下载的解决方式
linux·运维·centos
weixin_516023075 小时前
linux下fcitx5拼音的安装
linux·运维·服务器
hunter14505 小时前
Linux 进程与计划任务
linux·运维·服务器
楼田莉子6 小时前
Linux学习之磁盘与Ext系列文件
linux·运维·服务器·c语言·学习
陌上花开缓缓归以6 小时前
linux 怎么模拟系统panic重启
linux·运维·服务器