上传linux版本的mysql5.7.26包(可在官网下载)到服务器,上传文件前提要配置ftp服务,具体可参考如下链接
https://blog.csdn.net/qq_43560721/article/details/119607945
下面这个链接是我下载好的安装包
https://download.csdn.net/download/qq_43560721/21046800
解压
cd /home/ftp/ //找到服务器mysql压缩包所在位置
tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz //解压
移动并修改文件名
mv mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql
创建mysql用户组、用户
groupadd mysql
useradd -r -g mysql mysql
创建数据目录,赋权限
mkdir -p /data/mysql
chown mysql:mysql -R /data/mysql
my.cnf文件配置
vi /etc/my.cnf
i
修改后
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
#character config
character_set_server=utf8mb4
explicit_defaults_for_timestamp=true
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
按ESC键退出,shift+: ,再输入wq!保存文件
初始化数据库
cd /usr/local/mysql/bin/ //进入mysql的bin目录
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
将mysql服务放置到/etc/init.d/mysql后,启动。
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
service mysql start
ps -ef|grep mysql
用初始密码GaTzFprM-49Y 登录mysql,修改密码
./mysql -u root -p
输入初始密码
SET PASSWORD = PASSWORD('sxj795795'); //设置密码
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;//让密码永不过期
FLUSH PRIVILEGES;//mysql 新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问
为了避免我们在用数据库链接工具时无法链接ip的情况出现,执行下面
use mysql//使用数据库
update user set host = '%' where user = 'root';//root表示想要被连接的数据库的用户名,其中“%”表示允许所有机器能访问root用户
FLUSH PRIVILEGES;
尝试连接成功啦!