下载仓库地址
- 进入MySQL官网
https://www.mysql.com/
- 点击【Download】
- 鼠标滑动到页面底部,选择【MySQL Community (GPL) Downloads »】
4. 点击MySQL APT Repository
- 点击Download
- 点击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>