Mysql版本:8.3.0
Linux版本:Centos 8
1 下载mysql安装包
进入MySQL官网 >> downloads >> MySQL Community(GPL)Downloads
点击MySQL Community Server
根据Linux版本和服务器架构选择软件
# uname -m # 查看Linux架构
x86_64
2 解压安装包,上传文件
解压mysql-8.3.0-1.el8.x86_64.rpm-bundle.tar
只上传这几个安装包
3 卸载旧的mysql
如果没有安装过mysql,跳过这一步 Linux Centos 卸载Mysql-CSDN博客
4 安装Mysql
1) 安装
# su - root
# rpm -ivh mysql-community-common-8.3.0-1.el8.x86_64.rpm
# rpm -ivh mysql-community-client-plugins-8.3.0-1.el8.x86_64.rpm
# rpm -ivh mysql-community-libs-8.3.0-1.el8.x86_64.rpm
# rpm -ivh mysql-community-client-8.3.0-1.el8.x86_64.rpm
# rpm -ivh mysql-community-icu-data-files-8.3.0-1.el8.x86_64.rpm
# rpm -ivh mysql-community-server-8.3.0-1.el8.x86_64.rpm
如果安装mysql-community-server-8.3.0-1.el8.x86_64.rpm报错,mariadb包跟mysql冲突,需要卸载
error: Failed dependencies:
mariadb-connector-c-config is obsoleted by mysql-community-server-8.3.0-1.el8.x86_64
# rpm -qa | grep mariadb
# yum remove -y mariadb-connector-c-config
2) 初始化
# mysqld --initialize
# grep 'temporary password' /var/log/mysqld.log
A temporary password is generated for root@localhost: !Ib<2qzkr0.W # !Ib<2qzkr0.W是初始密码
# systemctl start mysqld # 启动mysql
# mysql -uroot -p # 初次登陆mysql
输入初始密码
mysql> ALTER USER USER() IDENTIFIED BY '密码'; # 修改初始密码
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 开启远程连接
# mysql -uroot -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
mysql> use mysql
mysql> select user,host from user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
mysql> update user set host="%" where user="root"; # 将root帐号的host设置为%
mysql> flush privileges; # 使本次修改立即生效
# systemctl stop firewalld # 关闭防火墙
如果是云服务器,需要在"控制台"放开对应端口