下载安装包:
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
下载依赖:
yum -y install libaio
解压安装:
tar -xvf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
cd /usr/local
mv mysql-8.0.30-linux-glibc2.12-x86_64/ mysql
创建mysql用户及组:
groupadd mysql
useradd -g mysql mysql
创建数据及日志目录:
mkdir /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
mkdir /var/log/mysql
chown -R mysql:mysql /var/log/mysql
mkdir /var/run/mysql
chown -R mysql:mysql /var/run/mysql
创建MySQL配置文件:
vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
user=mysql
port=3306
[mysqld_safe]
log-error=/var/log/mysql/mysql.log
pid-file=/var/run/mysql/mysql.pid
!includedir /etc/my.cnf.d
配置MySQL环境变量:
vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile
初始化MySQL:
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize-insecure --user=mysql
启动MySQL:
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
使用system管理MySQL(推荐):
vim /usr/lib/systemd/system/mysql.service
[Unit]
Description=mysql
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecReload=/usr/local/mysql/support-files/mysql.server restart
ExecStop=/usr/local/mysql/support-files/mysql.server stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
开机自启MySQL:
systemctl daemon-reload
systemctl enable --now mysql
登录MySQL并修改密码:
本地首次使用sock文件登录mysql是不需要密码的。
mysql -S /var/lib/mysql/mysql.sock
mysql> alter user 'root'@'localhost' identified by '123456';
mysql> flush privileges;
修改密码之后就不能用sock登录了
mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解决方法:
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
授予用户权限. 必须先要创建用户, 才能授权!!
mysql> create user 'nagao'@'localhost' identified by '123456';
mysql> grant all privileges on *.* to 'nagao'@'localhost' with grant option;
标签:MySQL8,MySQL,sock,二进制,部署,usr,mysql,var,local
From: https://www.cnblogs.com/haoee/p/16944366.html