MYSQL8安装:LINUX版本

零、系统

CentOS7 腾讯云服务器


一、安装

1.确定系统版本

uname -m					# 输出 x86_64
cat /etc/redhat-release		# 输出 CentOS Linux release 7.9.2009 (Core)


2.安装 yum 资源

rpm -ivh https://repo.mysql.com//mysql80-community-release-el7-7.noarch.rpm


3.查看 MySQL 当前版本

yum info mysql-community-server			# 8.0.33


4.安装 MySQL

yum -y install mysql-community-server

安装完成!!


二、启动

1.启动 MySQL 服务:

systemctl start mysqld.service

重启MySQL服务:

systemctl restart mysqld.service

查看 MySQL 运行状态:

systemctl status mysqld.service


2.获取 root 用户的密码:

grep "password" /var/log/mysqld.log


2023-05-10T01:41:41.632792Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: _ih4M9ogiXt%

# 其中最后的 _ih4M9ogiXt% 就是密码


如果查询不到密码,进入第三步


3.进入数据库:

mysql -u root -p # 初始密码为之前获取的 _ih4M9ogiXt%


修改新的密码:

# 密码设置必须要大小写字母数字和特殊符号

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';


重新进入数据库:

mysql -u root -p		# 使用修改过后的密码


三、无密码登录

1.编辑配置文件

编辑/etc/my.cnf文件,在末尾出增加 skip-grant-tables

重启mysql服务

systemctl restart mysqld

登录mysql,并重置root密码为空

2.登录mysql

mysql -uroot

3.修改root密码为空

use mysql;
update user set authentication_string='' where User='root';

5.刷新权限并退出

flush privileges;
quit;

将 /etc/my.cnf 中 的 skip-grant-tables 去掉;

6.再次重启mysql服务

7.再次登录mysql,登录密码为空,然后修改root密码

ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';


四、第三方工具无法连接

navicat连接报错

Host is not allowed to connect to this MySQL

1.修改/etc/my.cnf

打开my.ini,找到[mysqld]项,在其后加入一句:skip-name-resolve,保存,重启mysql服务即可


2.更新数据库用户

登录数据库执行

update user set host = '%' where user = 'root';


{context}