虚拟机centos7安装mysql8
虚拟机centos7安装mysql8.x
# 删除系统仓库
[root@localhost ~]# rm -rf /etc/yum.repos.d/*
# CentOS 7 更换阿里云软件仓库
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# 查看软件仓库最新情况
[root@localhost ~]# yum repolist
repolist: 16,771
# 下载wget
[root@localhost ~]# yum install -y wget
# 下载mysql源安装包
[root@localhost ~]# wget https://dev.mysql.com/get/mysql84-community-release-el7-1.noarch.rpm
# 安装mysql源
[root@localhost ~]# yum -y localinstall mysql84-community-release-el7-1.noarch.rpm
# 在线安装mysql
[root@localhost ~]# yum -y install mysql-community-server
# 启动mysql服务
[root@localhost ~]# systemctl start mysqld
# 设置开机自启
[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# systemctl daemon-reload
# 修改root本地登录密码
[root@localhost ~]# vi /var/log/mysqld.log
# 输入临时密码,进入mysql命令行
[root@localhost ~]# mysql -u root -p
# 修改root用户密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql_4U';
Query OK, 0 rows affected (0.01 sec)
# 建立root用户与密码
mysql> create user 'root'@'%' identified by 'mysql_4U';
Query OK, 0 rows affected (0.01 sec)
# 授予root用户所有权限
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)
# 刷新授权
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
# 退出
mysql> exit
# 开启防火墙3306端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@localhost ~]# firewall-cmd --reload
# 配置默认编码为UTF-8
[root@localhost ~]# vi /etc/my.cnf
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
# 重启mysql服务
[root@localhost ~]# systemctl restart mysqld
# 查看编码
mysql> show variables like '%character%';
+-------------------------------------------------+--------------------------------+
| Variable_name | Value |
+-------------------------------------------------+--------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb3 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb3 |
| character_set_system | utf8mb3 |
| character_sets_dir | /usr/share/mysql-8.4/charsets/ |
| validate_password.changed_characters_percentage | 0 |
+-------------------------------------------------+--------------------------------+
9 rows in set (0.02 sec)
# 打开navicat连接mysql
参考链接: