1. 下载Ubnutu 的mysql版本
mysql官网下载地址:https://dev.mysql.com/downloads/mysql/
2.上传解压缩和安装
将下载的mysql tar文件移动到服务器的根目录(根据自己实际目录情况移动合适位置)
tar -xvf mysql-server_5.7.40-1ubuntu18.04_amd64.deb-bundle.tar
压缩后将得到以下文件
3.使用dpkg -i 命令顺序安装deb包
dpgk -i xxxxxxxxxxxxx.deb ,可能会有权限,使用sudo dpgk -i xxxxxxxxxxxxx.deb
过程中可能会有依赖错误,先忽略继续,使用如下命令自动安装全部依赖
apt --fix-broken install
root@wdr: apt --fix-broken install
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
libmecab2 libtinfo5
The following NEW packages will be installed:
libmecab2 libtinfo5
0 upgraded, 2 newly installed, 0 to remove and 50 not upgraded.
3 not fully installed or removed.
Need to get 298 kB of archives.
After this operation, 1,432 kB of additional disk space will be used.
Do you want to continue? [Y/n]
同意继续后两次提示配置密码
当然 mysql的安装是完成了 但是此时它并不能为我们的程序提供服务(使用连接工具现在是连接不上的) 因为还需要配置远程连接 使我们可以远程登录才可以
首先 进入mysql库 查看user表 会发现我们的root用户是localhost
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>
mysql> select User,Host from user;
+---------------+-----------+
| User | Host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
mysql>
将其修改 并使其立即生效
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select User,Host from user;
+---------------+-----------+
| User | Host |
+---------------+-----------+
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
exit退出mysql命令界面,编辑mysqld.cnf,
root@wdr: vim /etc/mysql/mysql.conf.d/mysqld.cnf
键盘Insert,开始编辑,将其bind-address改为0.0.0.0,Esc退出bianji 输入 “:wq”,保存退出编辑
保存退出 重启mysql服务
root@wdr: systemctl restart mysql
最后注意服务器防火墙或端口是否开启受限制,造成mysql服务链接不通