1、下载并上传mysql rpm安装包
tar -xvf mysql-8.4.3-1.el7.x86_64.rpm-bundle.tar
2、按照如下顺序执行安装;如果有依赖缺少,执行yum -y install 依赖名称
rpm -ivh mysql-community-common-8.4.3-1.el7.x86_64.rpm rpm -ivh mysql-community-client-plugins-8.4.3-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-8.4.3-1.el7.x86_64.rpm rpm -ivh mysql-community-client-8.4.3-1.el7.x86_64.rpm rpm -ivh mysql-community-icu-data-files-8.4.3-1.el7.x86_64.rpm rpm -ivh mysql-community-server-8.4.3-1.el7.x86_64.rpm
3、修改配置文件
vi /etc/my.cnf
在[mysqld]组下添加如下内容
datadir=/data/program/mysql/data ##这个目录根据自己的实际情况而定port=3306sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION character-set-server=utf8 collation-server=utf8_general_ci lower_case_table_names=1 max_connections = 10000 mysql_native_password=ON skip-grant-tables ##修改完密码后注销掉该行,重启mysql
4、安装完成后会有mysql:mysql的用户;如果没有则手动添加mysql组和mysql用户
chown -R mysql:mysql /data/program/mysql/data ##my.cnf中的datadir目录
5、启动mysql,查看路径下是否有mysql数据文件
systemctl start mysqld
6、查看临时生成的密码,登陆后修改密码
cat /var/log/mysqld.log | grep 'temp'
mysql -uroot -p flush privileges; alter user 'root'@'localhost' identified with mysql_native_password by 'new_password';//新密码最低8位、大小写、特殊字符 flush privileges;
7、注释掉my.cnf里面的skip-grant-tables,然后重新启动mysql
systemctl restart mysqld
8、新增远程访问用户root或者其他名,建议使用别的名称
mysql -uroot -p #输入修改后的密码 use mysql; create user 'root'@'%' identified with mysql_native_password by '新密码'; grant all privileges on *.* to 'root'@'%'; flush privileges;
9、加入开机启动
systemctl enable mysqld
10、远程连接测试