ubuntu20.04安装mysql8并配置远程访问

本文详细介绍了在Ubuntu 20.04环境下安装和安全配置MySQL服务器的过程,包括设置root密码、移除匿名用户、禁止远程root登录、修改test数据库权限,并允许远程root用户通过iptables。最后,展示了如何配置MySQL远程访问和修改my.cnf文件以实现更安全的部署。
摘要由CSDN通过智能技术生成

环境:

ubuntu20.04

8.0.25-0ubuntu0.20.04.1

1.安装mysql

apt-get install mysql-server
apt-get install mysql-client

2.配置mysql

sudo mysql_secure_installation

按下面流程配置完成,主要是设置密码

root@ailyun:~# sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: n
Please set the password for root here.

New password:

Re-enter new password:
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. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : n

 ... skipping.


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

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
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
Success.

All done!

3.配置远程登入

// 登录数据库
mysql -u root -p
// 选择数据库
mysql> use mysql;
// 更改加密方式,passwd为数据库密码
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'pwsswd';
// 修改root用户为所有ip都可访问
update user set host='%' where user='root';
// 开户root用户的远程访问权限
grant all on *.* to 'root'@'%';
// 更新权限
flush privileges;

 修改配置文件

// 停止mysql服务,不然后配置文件不能保存
service mysql stop
// 打开配置文件
vim /etc/mysql/mysql.conf.d/mysqld.cnf

// 注释下面一行
# bind-address = 127.0.0.1

// 再启动mysql服务
service mysql start

 打开mysql workbench,选择Database -> Connect to Database,输入ip端口,用户名密码

 

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值