centos7离线安装mysql5.7

centos7离线安装mysql5.7

参考文章:https://www.cnblogs.com/yy3b2007com/p/10497787.html

1、去官网下载安装包

官网下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
版本:mysql-5.7.20-linux-glibc2.12-x86_64.tar
在这里插入图片描述

2、卸载CentOS7系统自带mariadb

# 查看系统自带的Mariadb
rpm -qa|grep mariadb

# 卸载系统自带的Mariadb
rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
# 删除etc目录下的my.cnf
 rm /etc/my.cnf

3、检查mysql在不在

rpm -qa | grep mysql

4、检查mysql组和用户是否存在,如无则创建(不知道这一步有什么用)

cat /etc/group | grep mysql
cat /etc/passwd | grep mysql 

若不存在,则创建mysql组和用户

创建mysql用户组

 groupadd mysql

#创建一个用户名为mysql的用户,并加入mysql用户组

useradd -g mysql mysql

制定password 为111111

 passwd mysql

然后就要输密码:
Changing password for user mysql.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.

5、用ftp工具上传下载的tar包

把解压好的tar包放到/usr/local/文件夹在这里插入图片描述
进入/usr/local下,修改为mysql

[root@localhost local]# mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql

6、更改所属的组和用户

[root@localhost local]# chown -R mysql mysql/
[root@localhost local]# chgrp -R mysql mysql/
[root@localhost local]# cd mysql/
[root@localhost mysql]# mkdir data
[root@localhost mysql]# chown -R mysql:mysql data

7、在/etc下创建my.cnf文件

[root@localhost mysql]# touch my.cnf
[root@localhost mysql]# vi my.conf

my.conf里面放这些

[mysql]
socket=/var/lib/mysql/mysql.sock
# set mysql client default chararter
default-character-set=utf8

[mysqld]
socket=/var/lib/mysql/mysql.sock
# set mysql server port  
port = 3323 #默认是3306,这里发现3306已经被占用,因此防止这种情况发生,可以避免使用3306mysql默认端口
# set mysql install base dir
basedir=/usr/local/mysql
# set the data store dir
datadir=/usr/local/mysql/data
# set the number of allow max connnection
max_connections=200
# set server charactre default encoding
character-set-server=utf8
# the storage engine
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
然后保存,退出。




###

8、进入mysql文件夹,并安装mysql

  [root@localhost mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

设置文件及目录权限:

[root@localhost mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chown 777 my.cnf
[root@localhost mysql]# ls
[root@localhost mysql]# chmod +x /etc/init.d/mysqld
[root@localhost mysql]# mkdir data
[root@localhost mysql]# chown -R mysql:mysql data

9、启动mysql

[root@localhost mysql]# /etc/init.d/mysqld restart
设置开机启动
[root@localhost mysql]# chkconfig --level 35 mysqld on
[root@localhost mysql]# chkconfig --list mysqld
[root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig --list mysqld
[root@localhost mysql]# service mysqld status

10、修改配置文件

# 进入/etc/profile文件夹
[root@localhost mysql]#vim /etc/profile
修改/etc/profile,在最后添加如下内容:
#set mysql environment
export PATH=$PATH:/usr/local/mysql/bin
然后保存
# 使文件生效
[root@localhost mysql]#  source /etc/profile

11、获得mysql初始密码

[root@localhost mysql]# cat /root/.mysql_secret

# Password set for user 'root@localhost' at 2020-07-16 15:04:58 
rWaheugBDI*7
[root@localhost mysql]# mysql -uroot -p
Enter password: 
mysql> set PASSWORD = PASSWORD('123456');
mysql> flush privileges;
mysql> exit

12、添加远程权限

mysql> use mysql
mysql> update user set host='%' where user='root';
mysql> select host,user from user;

13、重启mysql生效

 /etc/init.d/mysqld restart
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页