Linux安装
-
下载并安装MySQL5.7的yum源
[root@localhost ~]# wget -P /tmp https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm [root@localhost ~]# cd /tmp [root@localhost tmp]# rpm -ivh mysql57-community-release-el7-9.noarch.rpm 警告:mysql57-community-release-el7-9.noarch.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:mysql57-community-release-el7-9 ################################# [100%]
-
通过yum安装MySQL5.7
[root@localhost tmp]# yum install -y mysql-server 需要等待较长时间...
-
启动MySQL
查看mysql是否启动 [root@localhost tmp]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: inactive (dead) Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html 启动mysql [root@localhost tmp]# systemctl start mysqld 查看mysql是否启动 [root@localhost tmp]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 六 2020-05-30 18:28:14 CST; 2min 2s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 37102 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 37048 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 37105 (mysqld) CGroup: /system.slice/mysqld.service └─37105 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
-
初始化MySQL
查看初始随机密码 [root@localhost tmp]# head -n 10 /var/log/mysqld.log 2020-05-30T10:28:09.210385Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2020-05-30T10:28:09.906316Z 0 [Warning] InnoDB: New log files created, LSN=45790 2020-05-30T10:28:10.001119Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2020-05-30T10:28:10.064286Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 4245a568-a260-11ea-85b9-000c290150c5. 2020-05-30T10:28:10.067028Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2020-05-30T10:28:11.461525Z 0 [Warning] CA certificate ca.pem is self signed. 2020-05-30T10:28:11.839011Z 1 [Note] A temporary password is generated for root@localhost: o3DIit9dDr%n 2020-05-30T10:28:14.443528Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 登录mysql,并修改root账号的密码 [root@localhost mysql-rpm-5.7.29]# mysql -u root -p Enter password:粘贴随机初始密码 修改密码,注意:默认密码检查策略比较严格,必须定义如下类似密码 mysql> alter user 'root'@'localhost' identified by '$BAIZHIroot2002'; 修改为简单密码: 修改密码检查策略 mysql> set global validate_password_policy=0; mysql> set global validate_password_length=4; 修改root为简单密码 mysql> alter user root@'localhost' identified by '123456'; 设置root允许远程登录 mysql> use mysql; mysql> update user set host = '%' where user = 'root'; mysql> flush privileges;//一定要刷新操作