检查是否安装,如果安装则卸载
rpm -qa|grep mysql
rpm -e --nodeps
下载rpm包仓库
安装依赖
wget https://repo.mysql.com/mysql80-community-release-el8-1.noarch.rpm
rpm -ivh mysql80-community-release-el8-1.noarch.rpm
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
yum update
安装指定26版本
yum -y install mysql-community-server-8.0.26-1.el8.x86_64.rpm
安装指定最新版本
yum install mysql-server
安装后检查/etc/my.cnf,配置文件目录,是否包含:
!includedir /etc/my.cnf.d
vim /etc/my.cnf.d/mysql-server.cnf
--增加
lower-case-table-names=1
skip-grant-tables #配置完成后,需要删掉
chown -R mysql:mysql /var/lib/mysql/
systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld
systemctl enable mysqld.service
mysql
use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'tw369.com';
FLUSH PRIVILEGES;
mysql -uroot -p
设置Mysql远程访问账户密码
update user set host ="%" where user = "root";
flush privileges;
挂载盘符
fdisk –l
sudo mkfs.ext4 /dev/vdb --格式化
mount /dev/vdb /data --挂载
vim mount /dev/vdb /mnt
vim /etc/fstab --增加一行
/dev/vdb /data ext4 defaults 0 0 --自动挂载
转移数据
systemctl stop mysqld
mkdir /data/mysql
chown mysql:mysql /data/mysql
chmod 777 /data
chmod 777 /data/mysql
mv /var/lib/mysql/* /data/mysql/
vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
# datadir=/var/lib/mysql
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid
vim /data/mysql/mysqld.log
wq!
chmod 777 /data/mysql/mysqld.log
ln -s /data/mysql/mysql.sock /var/lib/mysql/mysql.sock --如果找不一mysql.sock,则建立软链接
systemctl start mysqld
systemctl status mysqld
systemctl status mysqld --查看状态
journalctl -xe --查看错误详细