欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mysql离线二进制安装

程序员文章站 2022-03-12 12:37:12
...

mysql离线二进制安装

清理环境:

# 检测是否安装过mysql
rpm -qa | grep mysql
# 删除命令
rpm -e --nodeps mysql-libs-5.1.73-5.el6_6.x86_64
# 清除相关文件夹
whereis mysql
rm -rf /usr/lib64/mysql /usr/share/mysql
find / -name mysql
rm -rf /etc/selinux/targeted/active/modules/100/mysql

1、下载安装包:(找个可以访问公网的机器下载,scp传给离线机)

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

2、创建用户

useradd -r mysql -M -s /bin/false

3、安装

tar zxf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
mv /usr/local/mysql-5.7.26-linux-glibc2.12-x86_64/  /usr/local/mysql
mkdir /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql/
cd /usr/local/mysql/
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

2021-11-08T16:53:40.303955Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-11-08T16:53:40.737310Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-11-08T16:53:40.826236Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-11-08T16:53:40.904487Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 6d06052a-40b4-11ec-890e-0800271838f4.
2021-11-08T16:53:40.965782Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-11-08T16:53:40.966618Z 1 [Note] A temporary password is generated for [email protected]: .Do+jldzK8t_
#初始密码:.Do+jldzK8t_

4、修改配置

vim /etc/my.cnf    #注释所有,再添加如下内容
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
socket=/usr/local/mysql/mysql.sock
character-set-server=utf8
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid
[mysql]
socket=/usr/local/mysql/mysql.sock
[client]
socket=/usr/local/mysql/mysql.sock

vim /etc/profile.d/mysql.sh 
export PATH=/usr/local/mysql/bin:$PATH  #写入此一行
#保存刷新
source /etc/profile.d/mysql.sh

cp support-files/mysql.server /etc/init.d/mysqld  #配置使用service mysqld start/stop/restart命令管理mysql
chmod +x /etc/init.d/mysqld    

vim /etc/init.d/mysqld
basedir=/usr/local/mysql    #第46行  补全安装目录
datadir=/usr/local/mysql/data  #第47行  补全数据所在目录

/etc/init.d/mysqld start        #启动

5、登录

#修改密码
mysqladmin -u root -p'初始密码'  password '新密码'  #新密码必须包含大小写英文、数字、特殊符号

#登录mysql
mysq -u root -p'新密码'