Centos8.4 二进制安装配置Mysql5.7.34
0. 下载安装包
https://dev.mysql.com/
下载后用lrzsz或winscp将安装包上传至服务器
1. 解压安装
yum install libncurses* -y
tar xf mysql-5.7.34-el7-x86_64.tar.gz -C /usr/local/
ln -sf /usr/local/mysql-5.7.34-el7-x86_64 /usr/local/mysql
useradd -u 306 mysql -s /sbin/nologin
chown mysql.mysql /data
chown mysql.mysql -R /usr/local/mysql
2. 初始化数据库文件
/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/data
初始密码为 ;oUm-z9iPgc;
3. 修改配置文件
cat > /etc/my.cnf<<EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/data
port=3306
socket=/usr/local/mysql/mysql.sock
pid-file=/usr/local/mysql/mysql.pid
EOF
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
vi /etc/init.d/mysqld
修改一下选项
basedir=/usr/local/mysql
datadir=/data
4. 启动Mysql服务
chkconfig --add mysqld
systemctl start mysqld
5. 进入Mysql
/usr/local/mysql/bin/mysql -uroot -p";oUm-z9iPgc;" --pid-file=/usr/local/mysql/mysql.pid
6. 重置root密码
alter user 'root'@'localhost' identified by '123456';
7. 处理一些报错
7.1 错误1:bash: mysql: command not found…
echo ‘PATH=/usr/local/mysql/bin:$PATH’ > /etc/profile.d/mysql.sh
7.2 错误2:ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’
vi /etc/my.cnf
追加以下内容
[client]
socket=/usr/local/mysql/mysql.sock