Ubuntu-20.04安装MySQL 8

下载仓库地址

  1. 进入MySQL官网
    https://www.mysql.com/
    在这里插入图片描述
  2. 点击【Download】
    在这里插入图片描述
  3. 鼠标滑动到页面底部,选择【MySQL Community (GPL) Downloads »
    在这里插入图片描述4. 点击MySQL APT Repository
    在这里插入图片描述
  4. 点击Download
    在这里插入图片描述
  5. 点击No thanks, just start my download.,或者复制其地址:https://dev.mysql.com/get/mysql-apt-config_0.8.24-1_all.deb
    在这里插入图片描述
cd /usr/local/src/
wget https://dev.mysql.com/get/mysql-apt-config_0.8.24-1_all.deb

安装

添加镜像库

dpkg -i mysql-apt-config_0.8.24-1_all.deb
apt update

安装MySQL 8

apt install mysql-server

设置用户

mysql -uroot

CREATE USER 'root'@'%' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
FLUSH PRIVILEGES;

  • 修改root@localhost密码不生效
ALTER USER 'root'@'%' IDENTIFIED BY '123456';

mysql -uroot还是能够登录?
问题可能是auth_socket认证引起的,执行以下命令查看是否为

mysql> select plugin,authentication_string from mysql.user where user = 'root';
+-----------------------+-------------------------------------------+
| plugin                | authentication_string                     |
+-----------------------+-------------------------------------------+
| auth_socket           |                                           |
+-----------------------+-------------------------------------------+
2 rows in set (0.00 sec)

mysql> 

这个时候只需要修改认证方式为mysql_native_password即可

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

mysql> select plugin,authentication_string from mysql.user where user = 'root'
    -> ;
+-----------------------+-------------------------------------------+
| plugin                | authentication_string                     |
+-----------------------+-------------------------------------------+
| mysql_native_password | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------------------+-------------------------------------------+
1 row in set (0.00 sec)

mysql> exit
Bye
root@VM-0-5-ubuntu:/home/lighthouse# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
root@VM-0-5-ubuntu:/home/lighthouse# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 8.0.31 MySQL Community Server - GPL

Copyright (c) 2000, 2022, 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> 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值