準(zhǔn)備用戶并創(chuàng)建目錄,準(zhǔn)備實(shí)驗(yàn)環(huán)境
[root@localhost ~]# groupadd -r -g 306 mysql
[root@localhost ~]# useradd -r -g 306 -u 306 -d /data/mysql mysql
[root@localhost ~]# mkdir /data/mysql
[root@localhost ~]# chown mysql:mysql /data/mysql
[root@localhost ~]# yum install -y libaio perl-Data-Dumper vim gcc gcc-c++ wget autoconf net-tools lrzsz curl policycoreutils openssh-server openssh-clients postfix
[root@localhost ~]# tar xf ~/mysql-5.7.29-el7-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@localhost ~]# source /etc/profile
開始安裝Mysql5.7
[root@localhost ~]# cd /usr/local/
[root@localhost ~]# mv /usr/local/src/mysql-5.7.29-el7-x86_64 /usr/local/mysql
[root@localhost src]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
2021-03-28T03:37:04.164075Z 1 [Note] A temporary password is generated for root@localhost: rk>bsXkum7ud
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# chkconfig --list |grep mysqld
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
[root@localhost ~]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/mysql_error.log'.
.... SUCCESS!
[root@localhost ~]# /usr/local/mysql/bin/mysql_secure_installation
更改密碼
驗(yàn)證
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29-log
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)