1、通过ftp工具将压缩包上传到linux服务器,下面是我存放的位置,你自己选择存放位置
2、解压
cd /usr/local #切换到安装包所在目录
tar -zxvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.30-linux-glibc2.12-x86_64 /usr/local/mysql
groupadd mysql
useradd -r -g mysql mysql
mkdir -p /data/mysql
chown mysql:mysql -R /data/mysql
记得备份这个文件
切换到这个文件所在目录:/etc
cp my.cnf my.cnf.default
vi /etc/my.cnf
[client]
port = 3306
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#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
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
切换到mysql安装目录的bin目录下
cd /usr/local/mysql/bin
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
ps:如果在初始化出现问题,如:
解决办法:
1、查看这个是不是存在:
rpm -qa|grep libaio
2、不存在的话安装一下
yum install libaio-devel.x86_64
1、先将mysql.server放置到/etc/init.d/mysql中
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
2、启动mysql
service mysql start
ps:启动会报错,因为找不到配置文件中的文件
下面是报错内容
解决办法:
创建文件并赋予权限
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb/
service mysql start
1、查看默认密码:
cat /data/mysql/mysql.err
./mysql -u root -p
ps:注意复制下面命令的时候,结尾的“;”需要手动输入
SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;
3、navicat远程登录
use mysql
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;
参考博文:https://blog.csdn.net/qq_37598011/article/details/93489404