mysql offline installation

1. Download the mysql offline installation package

Download page: https://downloads.mysql.com/archives/community/Download
address: https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.36-1.el7. x86_64.rpm-bundle.tar

Insert image description here

2. Upload to Centos7 server and decompress

tar -xvf mysql-5.7.36-1.el7.x86_64.rpm-bundle.tar
Insert image description here

3.Install mysql

# 1.先卸载服务器上的 mariadb 依赖
yum remove mariadb-libs
# 2.依次安装mysql rpm
rpm -ivh mysql-community-common-5.7.36-1.el7.x86_64.rpm;
rpm -ivh mysql-community-libs-5.7.36-1.el7.x86_64.rpm;
rpm -ivh mysql-community-libs-compat-5.7.36-1.el7.x86_64.rpm;
rpm -ivh mysql-community-devel-5.7.36-1.el7.x86_64.rpm;
rpm -ivh mysql-community-client-5.7.36-1.el7.x86_64.rpm;
rpm -ivh mysql-community-server-5.7.36-1.el7.x86_64.rpm --force --nodeps;

Insert image description here

  • After the four packages are installed, start the mysql service:
    systemctl start mysqld
    systemctl enable mysqld

  • Get the random password after startup: grep 'temporary password' /var/log/mysqld.log

  • Log in to mysql with a random password: mysql -uroot -p "password"

  • Enter the MySQL terminal to change the password

# 1.mysql密码安全规则(1.必须含有数字,小写或大写字母,特殊字符;2.最小长度为8)
set global validate_password_policy=0; #去掉1.必须含有数字,小写或大写字母,特殊字符规则
set global validate_password_length=1; #去掉2.最小长度为8规则

# 2.修改root密码
alter user 'root'@'localhost' identified by 'Root123456';

# 3.如果想root能远程访问
use mysql;
update user set host = '%' where user = 'root';      #使root能任何host访问
flush privileges;                                                       #刷新
  • Create a mysql user and set permissions
# 3.创建用户和赋权限
use mysql;
# 3.1.创建一个新用户 admin 密码为 Admin123456.
 CREATE USER 'admin'@'localhost' IDENTIFIED BY 'Admin123456.';
# 3.2.创建数据库testDB
 create database testDB;
# 3.3.为testuser用户添加使用testDB权限
 grant all privileges on testDB.* to admin@localhost identified by 'Admin123456.';
# 3.4.为testuser用户添加远程访问权限
  GRANT ALL PRIVILEGES ON testDB.* TO 'admin'@'%' IDENTIFIED BY 'Admin123456.' WITH GRANT OPTION;  
# 3.5.或者为用户添加所有数据库的权限
 grant all on *.* to admin@'%' identified by 'Admin123456.'; 
# 3.6.刷新权限表,使命令生效
 flush privileges;

View MySQL status: service mysqld status
Restart MySQL status: service mysqld restart

4. Uninstall mysql

//rpm包安装方式卸载
查包名:rpm -qa|grep -i mysql
删除命令:rpm -e –nodeps 包名
 
//yum安装方式下载
1.查看已安装的mysql
命令:rpm -qa | grep -i mysql
2.卸载mysql
命令:yum remove mysql-community-server-5.6.36-2.el7.x86_64
查看mysql的其它依赖:rpm -qa | grep -i mysql
 
//卸载依赖
yum remove mysql-libs
yum remove mysql-server
yum remove perl-DBD-MySQL
yum remove mysql

//删除残留文件(重要)
rm -f /var/log/mysqld.log
rm -rf /var/lib/mysql

5. Precautions

If it is MySQL8.0

注意,8.0版本这两个全局属性名称变化为: validate_password.policy和validate_password.length 
所以修改命令为: 
set global validate_password.policy=0; 
set global validate_password.length=1; 
再次修改就OK了

修改端口: vi /etc/my.cnf
 port=3308

重启mysql:service mysqld restart ,如果报错,可能是selinux问题,执行:setenforce 0

Guess you like

Origin blog.csdn.net/zhuyu19911016520/article/details/124168504