centos7下安装mysql 并开启远程服务

一. mysql官方给的安装文档https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

二 步骤: 

1.下载mysql社区版

(1)将MySQL Yum存储库添加到系统的存储库列表中

[root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

(2)安装下载的包

rpm -Uvh mysql80-community-release-el7-3.noarch.rpm

(3)通过手动编辑/etc/yum.repos.d/mysql-community.repo 文件来选择5.7版本(默认8.0)

vi命令

# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1 //将8.0的enabled改成0; 5.7的改成1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

(4)安装mysql 大约需要2到5分钟

yum install mysql-community-server

(5)启动mysql

systemctl start mysqld.service

(6)登录mysql

       [1] 获取初始化密码: grep 'temporary password' /var/log/mysqld.log

       [2]登录并输入密码: mysql -uroot -p

       [3] 更改密码mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码要求必须是' 特殊字符/大写/小写/数字缺一不可的' ;

       [4]exit退出,重新登录mysql -u$user -p $pwd

(7)开启远程

GRANT ALL PRIVILEGES ON *.* TO '$username'@'%' IDENTIFIED BY '$password' WITH GRANT OPTION;

(8)FLUSH PRIVILEGES;刷新权限

posted @ 2020-12-19 19:37  当当和瓶瓶  阅读(110)  评论(0编辑  收藏  举报