网址:https://dev.mysql.com/downloads/mysql/
Select Operating System: 选择 Red Hat(因为CentOS 是基于红帽的);Select OS Version: 选择 linux 7
下载第一个: mysql-8.0.20-1.el7.x86_64.rpm-bundle.tar
2. 点击 No thanks, just start my download. 进行下载,cp到虚拟机里
[root@zw ~]# cd /opt
[root@zw opt]# ls
mysql-8.0.20-1.el7.x86_64.rpm-bundle.tar
[root@zw opt]# mysqld --initialize
[root@zw mysql]# chown mysql:mysql /var/lib/mysql -R
[root@zw mysql]# systemctl start mysqld.service
[root@zw mysql]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2020-06-08 17:32:33 CST; 26s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 22395 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 22445 (mysqld)
Status: "Server is operational"
CGroup: /system.slice/mysqld.service
└─22445 /usr/sbin/mysqld
6月 08 17:32:02 zw systemd[1]: Starting MySQL Server...
6月 08 17:32:33 zw systemd[1]: Started MySQL Server.
6. 查看日志获取初始密码,连接mysql修改初始密码
[root@zw ~]# grep password /var/log/mysqld.log
2020-06-08T09:30:18.510275Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: pu4pj6bIBZ&g
[root@zw mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.20
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>
7.修改root,并开启远程访问(修改密码为Welljoint,123)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Welljoint,123';
Query OK, 0 rows affected (0.05 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> create user 'root'@'%' identified with mysql_native_password by 'Welljoint,123'; #开启远程登录授权
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.05 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql> exit
Bye