linux安装MySQL8.0详细教程
服务器环境是centos 7.5 ,通过yum方式安装。
1、安装依赖
yum install libaio wget -y
2、检查MYSQL是否已安装
yum list installed | grep mysql
3、若有则需卸载
格式: yum -y remove [包名]
yum -y remove mysql-libs.x86_64
4、下载MySQL官网的仓库文件
cd /tmp
wget http://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
yum localinstall mysql80-community-release-el7-1.noarch.rpm
5、验证仓库是否添加成功
yum repolist enabled | grep “mysql.-community.”
6、安装MySQL
yum install mysql-community-server -y
[7]、安装时如果报一下错误,则需下载(更新)mysql对应的gpgkey
cd /etc/pki/rpm-gpg
wget https://repo.mysql.com/RPM-GPG-KEY-mysql
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
或
cd /etc/pki/rpm-gpg
wget https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
若不清楚对应的gpgkey,可以两个都下载并导入。
8、此时MySQL 安装完成,它包含了
mysql-community-server、mysql-community-client
mysql-community-common、mysql-community-libs 四个包
执行以下命令,查看包信息,
rpm -qi mysql-community-server.x86_64
//注意不要跟上版本信息,如mysql-community-server.x86_64 0:8.0.28-1.el7
//空格后的字符会被判定为第二个要查找的包的名称(0:8.0.28-1.el7)
然后执行以下命令,查看安装目录
whereis mysql
启动服务
systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld
查找初始密码
cat /var/log/mysqld.log | grep password
执行以下命令,输入密码,进入mysql
mysql -uroot -p
修改初始密码
mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘[你的密码]’;
设置允许远程连接
mysql> use mysql;
mysql> select host,user,authentication_string,plugin from user;
mysql> update user set host=’%’ where user=‘root’;
mysql> flush privileges;
查看字符编码
mysql> status
若为utf8mb4则无需更改
完成
注:
参考博文:https://www.cnblogs.com/baoshu/p/centos-mysql.html
相比参考博文,完善了gpgkey更新步骤,完善了8中rpm -qi命令。