Ubuntu18简单安装配置MySQL远程访问

简介

Mysql做为一个开源的数据管理系统,经常用于LAMP或者LNMP集成安装包(Linux、Apache\Nginx、MySQL、

PHP)的一部分进行安装。使用它的关系数据以及SQL查询语句来管理数据库,这里我们演示一单独如何使用Ubuntu18

安装Mysql并进行简单的配置。

 

教程

安装Mysql

先来更新一下apt软件包

apt update

安装MySQL,默认安装的是apt软件包当中的最新版本

apt install mysql-server

 

配置Mysql

进行配置

mysql_secure_installation

配置时参数

#验证密码插件
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N 

#设置新密码
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 

#是否允许从本地登录
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) : Y 

#是否删除默认情况MySQL带有一个名为“test”的数据库
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 (我的选项)

#是否重新加载所做的更改立即生效
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 (我的选项)

检查Mysql状态

systemctl status mysql.service

使用root用户进入

mysql -uroot -p

其中root@localhos,localhost就是本地访问,配置成%就是所有主机都可连接

GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456";

 

配置mysql远程访问

Ubuntu下缺省是指允许本地访问MySQL,这里我们就需要进行配置远程访问让其他机器也可以访问

新建数据库做为远程用户使用

CREATE DATABASE ivpsr;

创建用户ivpsr(密码654321) 并允许ivpsr用户可以从任意机器上登入mysql的ivpsr数据库

GRANT ALL PRIVILEGES ON ivpsr.* TO ivpsr@"%" IDENTIFIED BY "654321"; 

后面可以使用workbench进行连接mysql数据库

THE END