MySQL mysql5.7-offline-install CentOS 7 MySQL5.7离线安装配置 MySQL5.7.24离线安装配置 卸载 CentOS 7 系统自带 mariadb 1 2 3 rpm -qa|grep mariadb rpm -e --nodeps [item] rm /etc/my.cnf 检查用户和组 不存在则创建 1 2 3 4 5 cat /etc/group | grep mysql cat /etc/passwd | grep mysql # 新增mysql用户组和用户 groupadd mysql useradd -r -g mysql -s /bin/false mysql 将mysql上传并解压 1 2 3 cd /usr/local/ tar -zxvf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz mv mysql-5.7.38-linux-glibc2.12-x86_64 mysql 更改所属的组和用户 1 2 3 4 5 6 cd /usr/local/ chown -R mysql mysql/ chgrp -R mysql mysql/ cd /usr/local/mysql/ mkdir data chown -R mysql:mysql data 创建my.cnf文件 1 vi /usr/local/mysql/my.conf 文件内容 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 [mysql] socket=/var/lib/mysql/mysql.sock default-character-set=utf8mb4 [mysqld] socket=/var/lib/mysql/mysql.sock port = 3306 basedir=/usr/local/mysql datadir=/usr/local/mysql/data max_connections=200 character-set-server=utf8mb4 default-storage-engine=INNODB lower_case_table_names=1 max_allowed_packet=16M explicit_defaults_for_timestamp=true [mysql.server] user=mysql basedir=/usr/local/mysql 安装mysql 1 2 3 4 /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile source /etc/profile 启动mysql 1 2 3 4 5 6 7 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chmod 777 /usr/local/mysql/my.conf chmod +x /etc/init.d/mysqld # 启动 /etc/init.d/mysqld restart # 重启 # /etc/init.d/mysqld restart 修改mysql初始密码 1 2 3 4 5 6 7 # 获取初始密码 cat ~/.mysql_secret # 登录 /usr/local/mysql/bin/mysql -uroot -p # 修改密码 set PASSWORD = PASSWORD('123456'); flush privileges;