MySQL安装和配置
1. 安装
-
检查mysql和mysql-server是否安装
rpm -qa | grep mysql rpm -qa | grep mysql-server
-
如果之前安装过进行卸载
yum -y remove mysql*
-
下载安装MySQL的repo源
https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpmwget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm rpm -ivh mysql80-community-release-el7-3.noarch.rpm
-
安装mysql 服务器(一路yes)
yum install mysql-community-server
-
安装成功后启动服务
systemctl start mysqld
-
查看默认密码
sudo grep 'temporary password' /var/log/mysqld.log
-
查看3306端口是否开放
netstat –ant
-
将mysql添加为自启动服务
systemctl enable mysqld
2. 配置
-
登录MySQL,密码为之前第6步查询出来的
mysql -u root -pxxx
-
修改 root 登录密码 (此时密码要根据密码规则设定)
alter user 'root'@'localhost' identified by 'xxx';
-
默认MySQL只允许localhost 登录,修改允许其他主机连接
CREATE USER 'root'@'%' IDENTIFIED BY 'password'; GRANT ALL ON *.* TO 'root'@'%'; FLUSH PRIVILEGES; ## 查看更新后数据 use mysql; select host, user, authentication_string, plugin from user;
-
创建其他用户并赋权
create user ‘用户名’@’访问主机’ identified by ‘密码’; grant 权限列表 on 数据库.表 to ‘用户名’@’访问主机’;(修改权限时在后面加with grant option)
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。