一、Linux下安装Mysql

百度

二、启动Mysql服务

1
2
3
4
5
6
7
service mysql start

service mysql stop

service mysql status

service mysql restart

三、登录Mysql

  1. mysql 安装完成后会有一个随机密码,并保存在一个密码文件中 :/root/.mysql_secret

  2. 登录后修改密码:

5.7版本: set password = password('新密码')
8.0版本: alter user 'root'@'%' identified by '123456'
3. 远程授权访问: grant all privileges on *.* to 'root' @'%' identified by '新密码';
4. 记住需要刷新:flush privileges;
若此时仍然不能连接上,则考虑Linux的防火墙。

四、用户权限

1
2
3
4
5
6
7
8
9
-- 授权全部权限,除了给别人授权权限, 库.表
grant all privileges on *.* to 用户名

-- 查看用户权限
show grant for 用户名

-- 撤销权限
revoke all privileges on *.* from 用户名