ubuntu20.04 安装mysql(8.x)

安装mysql命令

shell 复制代码
sudo apt-get install mysql-server

安装完毕后,立即初始化密码

shell 复制代码
sudo mysql -u root # 初次进入终端无需密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd'; # 设置本地root密码

设置mysql远程登录

  1. 设置远程登录账户
shell 复制代码
# mysql终端内执行
use mysql
update user set host = '%' where user ='root' and host = 'localhost';
flush  privileges;
  1. 配置mysql文件开启远程登录
    /etc/mysql/my.cnf
shell 复制代码
# 修改[mysqld]中的bind-address
直接注释 bind-address这一行
# bind-address>->---= 127.0.0.1
  1. 重启mysql服务
shell 复制代码
sudo service mysql restart

如果my.cnf显示这些不要慌,文件中最后两个includedir指向的是配置文件的路径,可以自己去看看mysqld.cnf在哪里再进行配置

我的在第二个/mysql.conf.d中

如果报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

解决方案:

shell 复制代码
sudo service mysql stop
sudo usermod -d /var/lib/mysql mysql
sudo service mysql start
相关推荐
qq_白羊座7 分钟前
口头说的 JSON 和 MySQL 里的 JSON
数据库·mysql·json
花间相见2 小时前
【计算基础|MySQL11】事务与隔离级别
sql·mysql·adb·架构
eleven_4u2 小时前
MySQL引擎层是如何工作的
数据库·mysql
计算机毕设定制辅导-无忧学长4 小时前
《基于微信小程序的个人智能刷题助手的设计与实现》
java·spring boot·mysql·微信小程序·uniapp·个人智能刷题助手系统
geovindu4 小时前
sql:Managing Complex Joins and Subqueries in SQL using mysql 9.0
大数据·数据库·数据仓库·sql·mysql·数据库开发·数据库架构
瑞克-桑切斯4 小时前
MySQL部署手册(5.7.20/8.0)
数据库·mysql
啵啵啵鱼5 小时前
九、JDBC 操作 MySQL 数据库
android·数据库·mysql
handonch5 小时前
MySQL → Kingbase PG模式 高频SQL替换清单
数据库·mysql·postgresql
水无痕simon5 小时前
15 MySQL是怎么保证高可用的?
数据库·mysql
张小姐的猫5 小时前
【MySQL】数据类型
android·linux·数据库·c++·mysql·adb·php