CentOS7下安装Mysql5.7(完整教程-yum源)

1、首先: 若之前装过mysql请先删除再进行安装:

Centos彻底卸载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远程连接数据库

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小达哥的垃圾桶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值