1, https://dev.mysql.com/downloads/mysql/5.7.html#downloads
到上述网址下载安装文件,选择linux-generic操作系统(使用uname -a查看主机信息选择64或32) 我们选择 mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz 这个版本进行安装
2,把下载的文件上传到 /usr/local/ 目录下面。使用下面指令查看压缩包的文件
tar -tf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz
3,解压压缩包
tar -zxvf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz
4,重命名文件夹
mv mysql-5.7.44-linux-glibc2.12-x86_64/ mysql/
5,添加群组
groupadd mysql
useradd -r -g mysql mysql
6,设置数据保存地址
mkdir -p /data/mysql #创建目录
chown mysql:mysql -R /data/mysql #赋予权限
7,编辑 /etc/my.cnf,添加如下类容
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql #/usr/local/mysql-5.7.34-linux-glibc2.12-x86_64
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
symbolic-links=0
explicit_defaults_for_timestamp=true
8,启动数据库:进入/usr/local/mysql/bin/ 执行如下指令
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
如果出现报错,需要安装下面两个插件
yum install -y libaio yum -y install numactl
9,将mysql.server放置到/etc/init.d/mysql中
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
10,启动数据库;
service mysql restart
如果提示 【The server quit without updating PID file】执行如下指令
touch /data/mysql/mysql.pid vim /data/mysql/mysql.pid
11,登录数据库(使用root账号登录,使用root账号的默认密码)
cat /data/mysql/mysql.err
./mysql -u root -p
如果提示【./mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No s】 执行如下指令
find / -name 'libncurses*'
ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5
12,修改默认密码、设置访问IP权限(已经成功登录mysql)
SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;
use mysql ;
update user set host = '%' where user = 'root'; #使root能在任何host访问
FLUSH PRIVILEGES;
update mysql.user set authentication_string=password('root_password') where user='root';
flush privileges;
13,如果不希望每次都到bin目录下使用mysql命令则执行以下命令
ln -s /usr/local/mysql/bin/mysql /usr/bin