-
下载 rpm 软件包
wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
-
安装
yum -y install mysql57-community-release-el7-10.noarch.rpm
-
更新安装的软件
yum update
-
安装 MySQL server
yum install mysql-server
-
运行 mysqld 并查看运行状态
systemctl start mysqld
systemctl status mysqld
-
查找默认密码
grep "password" /var/log/mysqld.log
-
以管理员身份进入mysql
mysql -u root -p
-
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
-
查看MySQL的所有用户及可连接的IP
SELECT host, user FROM mysql.user;
-- 结果显示类似于:
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
5 rows in set (0.00 sec)
-- 其中,% 表示所有IP均可访问,loocalhost 表示本地用户才可以访问
-
开通外网访问,% 表示所有 ip 均可访问,可改为指定 ip
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION; --已失效
-- 改为
create user 'root'@'%' identified by 'password'; -- 创建用户 root
grant all privileges on *.* to 'root'@'%'; -- 赋予 root 用户权限
-
更新规则
flush privileges;