一、安装前
1.检查是否已经安装mysql
rpm -qa | grep mysql
2.将查询出的包卸载掉
rpm -e --nodeps 文件名
3.将/usr/lib64/libLLVM-7.so删除
rm -rf /usr/lib64/libLLVM-7.so
4.检查删除结果
rpm -qa | grep mysql
5.搜索残余文件
whereis mysql
6.删除残余文件
rm -rf /usr/bin/mysql /usr/share/man/man1/mysql.1.gz
7.验证删除
whereis mysql
8.检查MySQL用户组以及用户是否存在,若没有则创建
cat /etc/group | grep mysqlcat /etc/passwd |grep mysqlgroupadd mysqluseradd -r -g mysql mysql
9.上传安装包
将mysql-8.0.33-linux-glibc2.17-x86_64-minimal.tar安装包上传到银河麒麟系统虚拟机中
二、安装
10.开始解压,在目录下/usr/local
tar -vxf mysql-8.0.33-linux-glibc2.17-x86_64-minimal.tar
11.重命名mysql文件夹
mv mysql-8.0.33-linux-glibc2.17-x86_64-minimal mysql
12.在目录下/usr/local/mysql/创建data目录
mkdir /usr/local/mysql/data
13.更改MySQL目录下所有的目录文件夹所属组和用户以及权限
chown -R mysql:mysql /usr/local/mysqlchmod -R 755 /usr/local/mysql
14.在/etc/目录下,创建一个my.cnf文件
[mysqld]datadir=/usr/local/mysql/databasedir=/usr/local/mysqlsocket=/usr/local/mysql/data/mysql.sockuser=mysqlport=3306character-set-server=utf8symbolic-links=0sql-mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid[client]port=3306socket=/usr/local/mysql/data/mysql.sock
15.编译安装并初始化MySQL数据库,并记录初始化后末尾输出的初始化密码
cd /usr/local/mysql/bin
./mysqld --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql --initialize
16.添加开机自启并开启服务
cp -rf /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldchmod +x /etc/init.d/mysqld/usr/lib/systemd/systemd-sysv-install enable mysqld
17.添加环境变量 vim /etc/profile
export MYSQL_HOME=/usr/local/mysqlexport PATH=$PATH:$MYSQL_HOME/bin
使环境变量生效
source /etc/profile
18.开启MySQL服务
systemctl start mysqld
19.查询服务状态
systemctl status mysqld
三、安装后
20.使用默认密码登录数据库
mysql -u root -p
21.修改密码
alter user 'root'@'localhost' identified by 'root';
刷新权限
flush privileges;
22.允许远程登录
update user set host ='%' where user ='root' and host = 'localhost';
刷新权限
flush privileges;
23.关闭防火墙
防火墙状态:
systemctl status firewalld.service
关闭firewall:
systemctl stop firewalld.service
禁止firewall开机启动:
systemctl disable firewalld.service
查看已经开放的端口:
firewall-cmd --list-ports
开启端口:
firewall-cmd --zone=public --add-port=80/tcp --permanent