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

环境:

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端口,用户名密码

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

 

上一篇:mysql8如何修改root密码


下一篇:CentOS8最全源码安装 LNMP - Mysql8 PHP8