1.删除系统自带MySQL和系统账号
rpm -ql mysql
rpm -ql mariadb
yum remove mariadb -y
userdel -r mysql
2.准备用户和数据库目录
groupadd -r -g 306 mysql
mkdir /data/mysql -p
useradd -r -g 306 -u 306 -d /data/mysql/ mysql
chown mysql:mysql /data/mysql/
3.安装MySQL
cd /opt/
tar zvxf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
ln -sv mysql-5.7.30-linux-glibc2.12-x86_64 mysql
chown -R root:root /usr/local/mysql
4.修改配置文件
[root@localhost mysql]# cat /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
# 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
[mysqld_safe]
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
5.安装依赖包(可能需要)
yum install libaio numactl-libs
6.配置变量数据库初始化及开机启动
echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
ln -s /usr/local/mysql/bin/* /usr/bin/
mysqld --initialize --user=mysql --datadir=/data/mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
ln -s /data/mysql/mysql.sock /tmp/mysql.sock
service mysqld start
ss -nlt
7.重置密码
mysqladmin -uroot -pFavr6F1X3n+t password magedu
8.如果不成功进入安全模式重置密码
mysqld_safe --skip-grant-tables &
199 20200818-103716:history
mysql> use mysql;
Database changed
9.手动update修改密码
mysql> update mysql.user set authentication_string=password("123456") where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye