首先登录到Ubuntu,这里不多说

1、安装mysql
参考:链接

命令1:sudo apt-get update
命令2:sudo apt-get install mysql-server mysql-client

中间会下载安装资源,大概十几秒

2、配置mysql
命令3:sudo mysql_secure_installation
初始化后,你可能会看到下面的内容

#1
VALIDATE PASSWORD PLUGIN can be used to test passwords…
Press y|Y for Yes, any other key for No: N (我的选项)

#2
Please set the password for root here…
New password: (输入密码)
Re-enter new password: (重复输入)

#3
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them…
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项)

#4
Normally, root should only be allowed to connect from
‘localhost’. This ensures that someone cannot guess at
the root password from the network…
Disallow root login remotely? (Press y|Y for Yes, any other key for No) :N(我的选项)

#5
By default, MySQL comes with a database named ‘test’ that
anyone can access…
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项)

#6
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选项)

上面的6点对着填y/n就可以。

命令4:systemctl status mysql.service
查看数据库状态,当然也可以不查

3、配置远程访问权限
此时只是安装好了数据库,但是并没有远程访问的权限,接下来配置权限
首先登录数据库
命令5:sudo mysql -uroot -p
回车输入上面第2步中第二条中自己设置的密码
然后进去
输入

配置开始

命令6:GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION;
注意两点,一个是末尾加分号,二是123456是我设置的密码,你们可以改成你们之前设置的密码

命令7:flush privileges;
刷新配置

接下来是最后一步,很关键,好多教程都是一笔带过,我在这里也停了好久,首先退出数据库,quit
然后

命令8:cd /etc/mysql/mysql.conf.d/

命令9:sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
修改mysqld.cnf配置文件,进去配置文件后
bind-address = 127.0.0.1 //找到此内容将ip改成0.0.0.0
保存退出
不会保存编辑配置文件的可以看这里 链接
以及这里 链接

到这里后,重启下系统再进入就安装配置好了

4、windows系统下navicat for mysql链接远程服务器
首先打开navicat
进入后新建连接,如下
ubuntu18.04安装mysql(2020最新)连接到navicat for mysql
上图说明:其中**主机名或者ip填你服务器的 内网ip **,密码是你数据库的密码

到ssh界面后如下图

ubuntu18.04安装mysql(2020最新)连接到navicat for mysql
这里的ip填你的外网ip,用户名是你服务器的用户名,密码是服务器的密码
最后登录就好了

相关文章: