centos7 安装mysql5.7
#切换yum源为国内镜像(切换国内镜像要速度快)
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
#安装
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
yum install -y mysql-community-server
#查看mysql状态
service mysqld status
# 启动mysql
service mysqld start
# 停止mysql
service mysqld stop
# 重启mysql
service mysqld restart
mysql5.7常用命令
#登录mysql
mysql -hhost -u username -p password
#创建用户
CREATE USER 'userName'@'host' IDENTIFIED BY 'password';
#为用户授权
grant all privileges on *.* to 'username'@'host' identified by 'password';
#刷新权限
flush privileges;
#忘记数据库密码解决方案
在my.ini中添加
skip-grant-tables
重启mysql:service mysqld restart
免密登录:mysql -u root
进入数据库:use mysql
修改root密码:
update user set authentication_string = password('新密码'),password_last_changed=now() where user='root';