Ubuntu20.0安装MySQL8并设置远程访问,Navicat连接测试成功

步骤
云服务器安全组设置
安装
检查MySQL是否正常启动
初始化
进入MySQL,修改一些配置
修改配置文件,以监听所有IP
本机使用 Navicat 连接
云服务器安全组设置
参考 腾讯云服务器Ubuntu20.0安装miniconda、jupyter,notebook设置中文和远程访问 中的第一步

安装
(base) ubuntu@VM-0-3-ubuntu:~$ sudo apt-get update
(base) ubuntu@VM-0-3-ubuntu:~$ sudo apt-get install mysql-server
… 输出了一大堆东西
下列【新】软件包将被安装:
libcgi-fast-perl libcgi-pm-perl libfcgi-perl libhtml-template-perl libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0
mysql-common mysql-server mysql-server-8.0 mysql-server-core-8.0
升级了 0 个软件包,新安装了 14 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
需要下载 30.9 MB 的归档。
解压缩后会消耗 258 MB 的额外空间。
您希望继续执行吗? [Y/n]
Y

检查MySQL是否正常启动
(base) ubuntu@VM-0-3-ubuntu:~$ systemctl status mysql
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2021-06-09 16:17:18 CST; 1min 51s ago
Main PID: 2886 (mysqld)
Status: “Server is operational”
Tasks: 37 (limit: 2328)
Memory: 332.4M
CGroup: /system.slice/mysql.service
└─2886 /usr/sbin/mysqld

6月 09 16:17:17 VM-0-3-ubuntu systemd[1]: Starting MySQL Community Server…
6月 09 16:17:18 VM-0-3-ubuntu systemd[1]: Started MySQL Community Server.

初始化
(base) ubuntu@VM-0-3-ubuntu:~$ sudo mysql_secure_installation

Securing the MySQL server deployment. 保护MySQL服务器部署。

Connecting to MySQL using a blank password. 使用空密码连接到MySQL。

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: 按y | y表示是,按其他键表示否:
N
Please set the password for root here. 请在此处设置root的密码。
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. 默认情况下,MySQL安装有一个匿名用户,允许任何人登录MySQL,而不必为他们创建用户帐户。这仅用于测试,并使安装更加顺利。您应该在进入生产环境之前删除它们。
Remove anonymous users? (Press y|Y for Yes, any other key for No) : 删除匿名用户(按y | y表示是,按其他键表示否):
Y
Success. 成功。

Normally, root should only be allowed to connect from ‘localhost’. This ensures that someone cannot guess at the root password from the network. 通常,只允许root用户从“localhost”连接。这确保了有人无法从网络中猜到根密码。

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : 不允许根用户远程登录(按y | y表示是,按其他键表示否):
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. 默认情况下,MySQL附带一个名为“test”的数据库,任何人都可以访问它。这也仅用于测试,应该在移入生产环境之前删除。
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : 删除测试数据库并访问它(按y | y表示是,按其他键表示否):
Y
- Dropping test database… -正在删除测试数据库。。。
Success. 成功。
- Removing privileges on test database… -正在删除对测试数据库的权限。。。
Success. 成功。
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 | y表示是,按其他键表示否):
Y
Success. 成功。
All done! 一切就绪!

进入MySQL,修改一些配置
(base) ubuntu@VM-0-3-ubuntu:~$ sudo mysql

如果出现错误,也可以试试:
(base) ubuntu@VM-0-3-ubuntu:~$ sudo mysql -u root -p
输入密码

选择use数据库
mysql> use mysql

查询user信息
mysql> select host,user,plugin from user;
±----------±--------------------------±--------------------------------+
| host | user | plugin |
±----------±--------------------------±---------------------------------+
| localhost | debian-sys-maint | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | root | auth_socket |
±-----------±-------------------------±---------------------------------+

设置root可远程访问(注意标点符号
mysql> update user set host=’%’ where user=‘root’;

修改root的认证方式和密码
mysql> ALTER USER ‘root’@’%’ IDENTIFIED WITH mysql_native_password BY ‘123456’;

刷新
mysql> FLUSH PRIVILEGES;

再次查询
mysql> select host,user,plugin from user;

退出
mysql> exit

修改配置文件,以监听所有IP
配置文件也有可能是别的,但都在 /etc/mysql 目录下
(base) ubuntu@VM-0-3-ubuntu:~$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
按 i 键,进入编辑模式
找到这两个,将其改为 0.0.0.0

保存并退出
按ESC键,再输入 :wq

重新启动MySQL服务
(base) ubuntu@VM-0-3-ubuntu:~$ sudo service mysql restart

本机使用 Navicat 连接

————————————————
版权声明:本文为CSDN博主「黑白吾尝」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_17517409/article/details/117746615

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章