当前位置: 首页 > article >正文

Ubuntu 20.04安装mysql8并配置远程访问

文章目录

  • 一、使用apt-get安装mysql服务
  • 二、初始化mysql数据库管理员用户密码
  • 三、配置远程访问


一、使用apt-get安装mysql服务

# 更新软件源
apt-get install update
# 安装mysql服务
apt-get install mysql-server
# 使用mysqladmin工具查看mysql版本
mysqladmin --version
# 启动mysql服务
systemctl start mysql
# 查看mysql服务运行状态
systemctl status mysql

二、初始化mysql数据库管理员用户密码

首先通过在root用户下执行 mysql 命令进入mysql命令行界面,然后执行SQL语句 alter user 'root'@'localhost' indentified with mysql_native_password by '密码'; 指定数据库管理员密码。

root@iZwz9fsfltolu74amg1v0rZ:/home/atreus# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.32-0ubuntu0.20.04.2 (Ubuntu)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> alter user 'root'@'localhost' indentified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye
root@iZwz9fsfltolu74amg1v0rZ:/home/atreus# 

管理员密码初始化完成后就能通过 mysql -u root -p 命令以root用户连接到数据库了。

root@iZwz9fsfltolu74amg1v0rZ:/home/atreus# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.32-0ubuntu0.20.04.2 (Ubuntu)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

三、配置远程访问

首先通过 vim /etc/mysql/mysql.conf.d/mysqld.cnf 命令打开mysql配置文件,找到 bind-address 将其修改为 0.0.0.0。修改完成后通过 systemctl restart mysql 重启mysql服务。

通过 mysql -u root -p 命令连接到数据库,然后依次执行以下SQL语句:

#切换数据库
use mysql;

#查看状态
select host, user, plugin from user;

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
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             | mysql_native_password |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)

mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
root@iZwz9fsfltolu74amg1v0rZ:/home/atreus# 

在本机测试远程连接:

在这里插入图片描述


参考:https://blog.csdn.net/weixin_38924500/article/details/106261971


http://www.kler.cn/news/17839.html

相关文章:

  • [EIS 2019]EzPOP
  • Dtop环球嘉年华全球Web3.0分布式私域电商生态发展峰会圆满举办
  • PHP检查目录是否存在?file_exists与is_file、is_dir的区别,以及执行效率的比较
  • 【MySQL--07】内置函数
  • 华为MPLS跨域C1方式RR场景(数据不经过RR)实验配置
  • 【软考数据库】第八章 数据库SQL语言
  • antd-vue - - - - - row-selection的使用
  • 智能座舱的“宏大蓝图”和“残酷现实”
  • 基于R语言的贝叶斯时空数据模型技术应用
  • 3.20 makefile的条件判断及函数使用
  • Nginx基础配置详解(main、events、http、server、location)
  • 圣杯布局和双飞翼布局
  • 企业遇到知识管理困境该怎么办?这里有解决方案!寻找Baklib
  • 一文搞懂TS中的泛型
  • 【Unity编辑器】拓展Inspector视图
  • 【Python百日进阶-Web开发-Feffery】Day617- 趣味dash_17:微型系统--引入flask-login
  • vue+node.js高校青年志愿者管理系统
  • AI来势汹汹,这份「生存计划」请查收!
  • 搭建vue3+vite工程
  • HTTPS协议介绍
  • 4.4——多重继承
  • 树形结构的三级分类如何实现?
  • 如何训练自己的大型语言模型
  • powershell定义文本,用户交互,正则表达式
  • 宝塔面板搭建自己的网站,并发布公网远程访问
  • 企业服务管理(ESM)工具
  • MySQL中的Join 的算法(NLJ、BNL、BKA)
  • XXLJOB
  • 知识变现海哥|这3种课程定价最容易爆单
  • asp.net+sqlserver企业财务管理系统