1、首先: 若之前装过mysql请先删除再进行安装:
2、安装wget
yum -y install wget
3、下载mysql的源
wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
4、安装yum库
yum localinstall -y mysql57-community-release-el7-7.noarch.rpm
5、安装MySQL
yum install -y mysql-community-server
6、启动MySQL服务
systemctl start mysqld.service
7、查看mySQL服务状态
systemctl status mysqld.service
8、MySQL5.7在安装时第一次安装后会初始化一个随机密码,以下为查看初始随机密码的方式
grep 'temporary password' /var/log/mysqld.log
9、先通过上面的密码来登录mysql并修改密码
mysql -u root -p
10、如果报错
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
/etc/rc.d/init.d/mysqld: line 259: cd: /usr/local/mysql: No such file or directory
######1、先停止服务
[root@ecs-dc15 src]# systemctl stop mysqld.service
[root@ecs-dc15 src]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Thu 2020-05-07 10:58:16 CST; 1s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
May 07 10:39:43 ecs-dc15 systemd[1]: Starting LSB: start and stop MySQL...
May 07 10:39:43 ecs-dc15 systemd[1]: Started LSB: start and stop MySQL.
May 07 10:58:16 ecs-dc15 systemd[1]: Stopped MySQL Server.
#####2、重新开启
[root@ecs-dc15 src]# systemctl start mysqld.service
[root@ecs-dc15 src]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-05-07 10:58:31 CST; 1s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 7653 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 7600 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 7656 (mysqld)
CGroup: /system.slice/mysqld.service
└─7656 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
May 07 10:58:26 ecs-dc15 systemd[1]: Starting MySQL Server...
May 07 10:58:31 ecs-dc15 systemd[1]: Started MySQL Server.
11、回到第8步,查看初始密码并修改密码
输入修改密码的命令:ALTER USER 'root'@'localhost' IDENTIFIED BY 'your password';
注意:mysql5.7默认密码策略要求密码必须是 大小写字母 ,数字 ,特殊字母的组合,至少8位
设置mysql可以被远程连接,在mysql中运行命令:
在mysql中运行:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION;
云服务器的话,要去控制台修改安全组配置,添加3306端口开放
最后,用Navicat远程连接数据库