//删除默认的mariadb
[root@localhost mysql]# rpm -qa | grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@localhost mysql]# rpm -e mariadb-libs --nodeps
[root@localhost ~]# ls
anaconda-ks.cfg mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# tar zxf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# mv mysql-5.7.29-linux-glibc2.12-x86_64 /usr/local/mysql
//创建用户组、创建数据库目录
[root@localhost ~]# cd /usr/local/mysql/
[root@localhost mysql]# groupadd -r mysql && useradd -r -g mysql -s /bin/false -M mysql
[root@localhost mysql]# mkdir data
[root@localhost mysql]# chown -R mysql:mysql .
//优化路径
[root@localhost mysql]# tail -1 /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
[root@localhost mysql]# . /etc/profile
//创建配置文件
vim /etc/my.cnf 查看mysql配置文件
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
server_id = 1
socket = /tmp/mysql.sock
#socket = /usr/local/mysql/mysql.sock
log-error = /usr/local/mysql/data/mysqld.err
pid-file = /usr/local/mysql/data/mysql.pid
//初始化
[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
//配置自启动
[root@localhost ~]# cd /usr/local/mysql/support-files/
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@localhost support-files]# netstat -anput | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 2756/mysqld
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig --level 345 mysqld on
[root@localhost ~]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
//登入并修改密码
[root@localhost support-files]# grep password /usr/local/mysql/data/mysqld.err
2020-11-21T11:18:07.463015Z 1 [Note] A temporary password is generated for root@localhost: Z1oS=zHGPDfW
[root@localhost support-files]# mysql -uroot -p'Z1oS=zHGPDfW'
mysql> alter user root@localhost identifide by '123.com';