CentOS快速安装Mysql5.7(Alibaba Cloud Linux兼容)

1、安装

在线下载
http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

下载rpm安装包

[root@theo bin]# cd /usr/local
[root@theo local]# wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

安装rpm

[root@theo local]# rpm -ivh mysql57-community-release-el7-10.noarch.rpm

原因是Mysql的GPG升级了,需要重新获取

[root@theo local]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

通过yum指令安装mysql服务 (下载安装mysql)

[root@theo local]# yum -y install mysql-community-server

将mysql加入到开机启动项 (mysql安装之后,在linux中的服务名为 mysqld)

[root@theo local]# systemctl enable mysqld

启动MySQL

[root@theo local]# systemctl start mysqld

检查3306端口是否被mysql占用

[root@theo local]# lsof -i:3306
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  3192 mysql   17u  IPv6  42484      0t0  TCP *:mysql (LISTEN)

停止MySQL

[root@theo local]# systemctl stop mysqld

2、修改初始密码

在Linux中安装MySQL并没有提示设置root用户的密码,安装包中设置了一个默认随机密码;但是这个默认随机密码只能用来初始登录,不能用来进行数据库操作(默认密码必须改)

1.查询初始密码

[root@theo local]# cat /var/log/mysqld.log | grep password
2021-01-16T06:41:27.753855Z 1 [Note] A temporary password is generated for root@localhost: gpKBe-Oqj6SD

2.登录mysql

[root@theo log]# mysql -uroot -p
Enter password: (粘贴复制的初始密码--回车)

3.修改初始密码
如下将密码修改为admin123

mysql> set global validate_password_policy=LOW;
Query OK, 0 rows affected (0.00 sec)

mysql> set password=password('admin123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

4.mysql的root账号默认不允许远程连接——授权远程连接

GRANT ALL PRIVILEGES on *.* to 'root'@'%' IDENTIFIED by 'admin123' WITH GRANT OPTION;

授权之后刷新权限

flush PRIVILEGES;

你可能感兴趣的:(Linux及环境配置,数据库MYSQL,linux,centos,adb)