centos 7.5 安装mysql 5.7
1. 更新yum
yum -y update
2. 下载mysql安装包
rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
3. 安装mysql
通过Yum来安装MySQL,会自动处理MySQL与其他组件的依赖关系
yum install -y mysql-server
4. 设置开机启动
systemctl enable mysqld.service
5. 设置开启服务
systemctl start mysqld.service
6. 查看默认密码
grep 'temporary password' /var/log/mysqld.log
7. 登录mysql
mysql -uroot -p
8.修改当前用户密码
SET PASSWORD = PASSWORD('Abc123!_');
9.开启远程登录权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Abc123!_' WITH GRANT OPTION;
10.刷新立即执行
flush privileges;
11. 添加一个root用户,密码暂时为空,允许任意Ip访问’%’
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Abc123!_' WITH GRANT OPTION;
12. 修改一下root用户的密码
update user set password=PASSWORD('Abc123!_') where user='root';
13.刷新立即执行
flush privileges;
其他常用命令
查看MySQL安装目录
whereis mysql
启动MySQL服务
systemctl start mysqld
关闭MySQL服务
systemctl stop mysqld
查看MySql默认密码
grep 'temporary password' /var/log/mysqld.log
查看MySQL服务状态
systemctl status mysqld
查看所有数据库用户
SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user